int and int* are two different types, just like float is a different type from int...
char* a, b, c; is a wrong way to do it (ACCORDING TO ME) since it is rubbish and all that, go with more whitespace and everyone will read it equally!

>> Although, I guess it would be just as easy to use the horizontal scroll bar to move over if it's indented a lot... Maybe that would ........ off the vi people enough to switch to a real IDE.

Yeah, I use a Scintilla-based IDE and it definitely has issues with horizontal scrolling (read: convulses). What do you use, by the way?

On Windows I use VC++ & Eclipse.
On Linux I just use Eclipse, although I haven't had to do much C++ in my new all UNIX work environment, only Java, Perl... but it looks like Eclipse has a plugin for almost everything.

Originally Posted by ಠ_ಠ

how would you make 3 pointers consistent with your interpretation with *?

I'd do this:

Code:

int* p1 = NULL;
int* p2 = NULL;
int* p3 = NULL;

I never declare more than one variable on a line and I always initialize my variables.

"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

And what about declaring your variables as close as possible to their first use? If you declare them all on one line at the top of your functions, you've been using C for too long.

Isn't initialization "use"? I won't bother arguing that tho.

But do you see what I see, vis, allmanism leading to further perversion? Even in "complex sources" I've looked at, *most* functions do not need to be more than 20-50 lines. I'm working in perl right now, which is constantly declaring "my" variables in blocks of scope. That's alright 'cause perl saves a lot, declaration wise, with sigils & dynamism. But,
if my functions
double in line length
suddenly I see people wanting
to declare in each block, because now what
supposedly made reading easier, needs to
compensate for the ways in which
it makes reading harder.

Which is ass backward. Because instead of compressing all your variable declarations into one paragraph at the beginning, you now have to add *more* vertical insertions...because you had *too many* to start with.

Congrats -- you've won me over on this one. I'm gonna start to use char* ptr instead of char *ptr. The later was just a habit I started out with.

But wait... the * binds to the name in the grammar!

Heheh, I tend to use T* name in C++ and T *name in C. Selective consistency

EDIT:

Originally Posted by MK27

Because instead of compressing all your variable declarations into one paragraph at the beginning, you now have to add *more* vertical insertions...because you had *too many* to start with.

If you had too many variables to start with, you should create a helper function, not change your indent style.

Declaring variables near first use means that the variable lives in the tighest scope possible. This use of local scope makes it easier to reason about your programs, and is precisely the point for local variables. Another reason would be to avoid unnecessary work, e.g., performing some relatively expensive initialisation prematurely (but I would regard this as more of a C++ problem due to potentially expensive constructors... unless you are a dumb C programmer).

EDIT #2:
Oh, and I have been informed:
*closed by request of the OP*

Last edited by laserlight; 06-16-2009 at 11:33 PM.

Originally Posted by Bjarne Stroustrup (2000-10-14)

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.