Re: Coding style survey
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 01/30/04
- Next message: J. J. Farrell: "Re: Is memcpy secure?"
- Previous message: Larry Doolittle: "Re: itoa in pure C"
- In reply to: Old Wolf: "Re: Coding style survey"
- Next in thread: Tom St Denis: "Re: Coding style survey"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 29 Jan 2004 19:06:04 -0500 (EST)
On Thu, 29 Jan 2004, Old Wolf wrote:
> [Arthur wrote:]
> > char c, *p, q, *x;
> >
> > or whatever it really was; I'm not going to take the time to look
> > back right now. I maintain that this is a Bad Idea.
>
> What do you think of
> char , *p[], q(), *x;
> then? :)
Slightly better, in that the compiler will refuse to compile it,
rather than let it sit on your disk misleading future programmers. :)
> Recently I wrote some code like:
>
> const unsigned char s[] = {
> foo(1),
> foo(2),
> /* ... (about 10 entries) */
> }, *ps = s;
>
> so that later on I could iterate with ps, or use the results
> from the functioncalls in many places. Using this syntax
> avoided having to type out "const unsigned char" twice (or use typedef)
Ooh, dear, typing 'const unsigned char' twice! ;-) Anyway, this
sort of thing is one of very few exceptions to the general rule.
I have seen and appreciated the idiom
typedef struct foo { bar blah; } foo, *pfoo;
even though I would obviously prefer to write
typedef struct foo foo;
typedef foo *pfoo;
struct foo { bar blah; };
in such situations, if they ever arose in my own code. And it's
possible to get borderline cases like the one you describe, even
in real code. But I'd still write
const unsigned char s[] = {
foo(1),
foo(2),
/* ... (about 10 entries) */
};
const unsigned char *ps = s;
in code meant for human consumption. The extra 'const unsigned char'
is quick to code, in an editor with cut-and-paste; and if you are
seriously concerned that 'unsigned char' may change in future versions,
you should be using a typedef anyway.
-Arthur
- Next message: J. J. Farrell: "Re: Is memcpy secure?"
- Previous message: Larry Doolittle: "Re: itoa in pure C"
- In reply to: Old Wolf: "Re: Coding style survey"
- Next in thread: Tom St Denis: "Re: Coding style survey"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|