How do you like to indent the CASE statement?
Pages: 1 2
Patrick M (2888) 126 posts |
Thanks for the replies everyone.
That reminds me. While we’re at it, when declaring pointers in C, where do you put the star? This is what I usually do when declaring pointers:
and this is what I do when when I have a function that returns a pointer:
I’m quite new to C, so I haven’t thought very hard about why I do it like that. I’ve seen people do it different ways, so I’m wondering, how do you do it? |
Chris Mahoney (1684) 2165 posts |
I always use “type *name” notation regardless of whether or not it’s a function. I learned that notation back in school and it’s stuck. |
Andy S (2979) 504 posts |
I started out usually putting the star against the type, the thinking being that it’s a pointer that’s being declared, like: int* point; For a while after learning more of the issue I hedged my bets: int * point; But now I try to use whatever the standard is for the project I’m working on, but when starting my own project I put the star against the variable name: int *point; Why? Because if you want to declare a list of pointers on one line, you need to repeat the star for each variable because it applies to the variable name, not the type: int *a, *b, *c; |
Christopher Bazley (2559) 6 posts |
‘int* point’ suggests that the author of the code either doesn’t know the C language’s grammar or wishes it were different. Neither of those possibilities inspires confidence! |
Rick Murray (539) 13850 posts |
Exactly. And the idea of suffixing the asterisk to the variable type falls apart here: int* one, two; where the two variables created are very much not the same. [saying what Andy said, in a different way ☺] |
Colin (478) 2433 posts |
I use when I cast a pointer I use
so |
Tristan M. (2946) 1039 posts |
Words can’t describe how much I hate the nuances of C syntax. I think it’s why I’ve never felt entirely comfortable using it. FreePascal on the other hand… I really like their version of Pascal. Probably because it’s actually useful unlike some other dialects. What I was going to say is that things like pointers, variable declaration etc is a lot more readable. I guess I’m just saying that C can be unpleasant to look at and sometimes confusing, especially where multiplication and pointers occur on the same line. |
Rick Murray (539) 13850 posts |
Ah, yes, Pascal. Where they had to botch in @ and ^ since the original spec didn’t want you to do such unsafe things as deal with addresses and pointers, leaving indirected pointers to be a mess compared to C’s . vs → syntax. As for multiplication and pointers on the same line, it isn’t too hard. Remember the compiler’s parser is braindead. Just omit one single } and you’ll see what I mean… |
Pages: 1 2