use of C99
Premi, Sanjeev sez,
Quoted 21 lines
I was referring to declaring variable within #ifdefs with belief that
use will be contained.e.g.
#ifdef CONFIG_COOL_FEATURE int i; int* ptr ; ... ...#endif
...
... 2 screenful down; in same function...
...#ifdef CONFIG_HOT_FEATURE u32 i; void* ptr; ... ...
Quoted 4 lines
#endif
Maybe for sometime the usage seems contained. Until someone decides to have both the COOL and HOT feature.
Pops out of hole, looks at shadow, 6 more weeks till we ship...
Um... my feeling is that if one is going to declare a variable inside a #ifdef then that variable ought to be called something like
int indx_CONFIG_COOL_FEATURE
and
u32 indx_CONFIG_HOT_FEATURE
Matt Harper
Tehama Wireless
Pink Boy wrote:
[snip]
Quoted 6 lines
Pops out of hole, looks at shadow, 6 more weeks till we ship...
Um... my feeling is that if one is going to declare a variable inside a #ifdef then that variable ought to be called something like
Quoted 8 lines
int
indx_CONFIG_COOL_FEATUREand
u32
indx_CONFIG_HOT_FEATUREMatt Harper
Tehama Wireless
EWWWWwww. Quoting from Documentation/CodingStyle:
------------------------------------------------------------------------
Chapter 4: Naming
C is a Spartan language, and so should your naming be. Unlike Modula-2 and Pascal programmers, C programmers do not use cute names like ThisVariableIsATemporaryCounter. A C programmer would call that variable "tmp", which is much easier to write, and not the least more difficult to understand.
[snip]
LOCAL variable names should be short, and to the point. If you have some random integer loop counter, it should probably be called "i". Calling it "loop_counter" is non-productive, if there is no chance of it being mis-understood. Similarly, "tmp" can be just about any type of variable that is used to hold a temporary value.
If you are afraid to mix up your local variable names, you have another problem, which is called the function-growth-hormone-imbalance syndrome. See chapter 6 (Functions).
------------------------------------------------------------------------
Best regards,
gvb
Dear Pink Boy,
Quoted 10 lines · In message <[email protected]> you wrote:
Um... my feeling is that if one is going to declare a variable inside a #ifdef then that variable ought to be called something like
int
indx_CONFIG_COOL_FEATUREand
u32
indx_CONFIG_HOT_FEATURE
Then please read the Coding Style about how to chose variable names.
Best regards,
Wolfgang Denk
Signature · 4 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de Imitation is the sincerest form of plagarism.
Quoted 11 lines · Wolfgang Denk
Dear Pink Boy,
Quoted 8 lines · In message <[email protected]> you wrote:
Um... my feeling is that if one is going to declare a variable inside a #ifdef then that variable ought to be called something like
int
indx_CONFIG_COOL_FEATUREand
Quoted 7 lines
Quoted 1 line
u32
indx_CONFIG_HOT_FEATUREThen please read the Coding Style about how to chose variable names.
Best regards,
Wolfgang Denk
No matter how many times I like at the code snippet above, my brain insists on seeing two #define constants named "CONFIG_COOL_FEATURE" and "CONFIG_HOT_FEATURE".
I once tried to deal with C code whose author had used some all-caps variable names. It was like getting a rental car with the gas pedal on the left and the break on the right. No matter how aware intellectually you were of this quirk, the car would be virtually undrivable. That's one reason consistent coding styles are important.
The brain also has a harder time dealing with two things that are almost the same than with two things that differ greatly. For example, if I knew French, I'm sure I would have no difficulty writing "centre". However, being a native speaker of American English, if I needed to write with traditional British spelling, I'm sure I'd screw up and writer "center" for "centre" at least half the time.
Personally, I prefer allowing variables to be declared anywhere, but I don't want the hidden cost of allowing U-Boot to be a little bit different from the Linux kernel to be underestimated. There is one place the styles differ already -- the use of a space between a function name and the following left parenthesis. The result is a mishmash, and just makes it harder to search the code base for function names.
Best regards,
Larry