K&R Style

Is there a way to turn this off, it is SO 1978.....

MacBook Pro, Mac OS X (10.6.4)

Posted on Aug 6, 2010 7:23 AM

Reply
12 replies

Sep 1, 2010 7:43 AM in response to gordingin

OK. Let's take a step back here. We are getting nowhere and taking forever to get there. This thread is almost a month old. Let's wrap it up.

K & R Style C refers to the C language as defined in the 1st edition of Kernighan and Ritchie's C Programming Language book. The following is correct K & R C syntax:

#include <stdio.h>
foo(str, value)
char * str; int value;
{
printf("String: %s, int: %d ", str, value);
return value;
}


Any C compiler should accept this without errors. The 2nd edition of Kernighan and Ritchie's book was based on the new "ANSI" version of C. The biggest change is the funky function definition.

Classes did not exist in either version of the C programming language.

I have not seen K & R "in the wild" since the first and last time I wrote some in 1997 when I was working on a project for a customer who wanted it done in "C", and not that new-fangled "ANSI" version. I wrote a very nice object-oriented K & R C program for him.

So, can you explain, by way of a concrete example, what you are talking about? Please, no more 3 word responses.

Sep 1, 2010 9:50 AM in response to gordingin

gordingin wrote:
I thought K&R was

int foo() {
}

that FIRST bracket...

I like it like

int foo()
{
}


Oh no. That is just style. In fact, the style:


int foo() {
}

is probably the most preferred/common style, I'm sorry to say. I agree with you. I actually prefer:

int foo()
{
}

but I can live with

int foo()
{
}

This one really bugs me

int foo() {
}


Alas, we are in the minority.

You might like this little thing I put together: http://etresoft.org/etrecode.html

You can also edit the Xcode text macros: http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/X codeWorkspace/100-TheText_Editor/text_editor.html#//appleref/doc/uid/TP40002679-SW43

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

K&R Style

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.