Re: Obfuscation devices (was Name Space Pollution: using macros ...)
From: Dave Vandervies (dj3vande_at_csclub.uwaterloo.ca)
Date: 10/14/03
- Next message: Christopher Benson-Manica: "Re: Embedded Vs Java"
- Previous message: John Bode: "Re: How to call appropriate functions?"
- In reply to: Arthur J. O'Dwyer: "Re: Obfuscation devices (was Name Space Pollution: using macros ...)"
- Next in thread: Jun Woong: "Re: Obfuscation devices (was Name Space Pollution: using macros ...)"
- Reply: Jun Woong: "Re: Obfuscation devices (was Name Space Pollution: using macros ...)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 14 Oct 2003 20:50:37 +0000 (UTC)
In article <Pine.LNX.4.58-035.0310141615590.14355@unix48.andrew.cmu.edu>,
Arthur J. O'Dwyer <ajo@nospam.andrew.cmu.edu> wrote:
>
>On Tue, 14 Oct 2003, Ben Pfaff wrote:
>> Follow along, please: that's the point. Dan claimed that
>> #define'ing a keyword is portable as long as it is done after
>> header inclusion. I said it's not and showed an example.
>
>Well, really Dan only said that
>
>#define int double
>
>was portable (as long as, etc). So you could have given a
>counterexample to *that* statement, instead of the general
>case (which I'm sure Dan considered). Can constant expressions
>contain casts? In that case,
>
>#define NULL ((void*)((int)1-1))
>
>could break Dan's *actual* suggestion, as well. Or even
>
>#define NULL ((void *)(sizeof(int)-sizeof(int)))
>
>which I *know* is a correct definition of NULL (don't I?).
I don't see the #define that Dan suggested breaking this. After expanding
the "int" macro, it would become:
#define NULL ((void *)(sizeof(double)-sizeof(double)))
sizeof(double) will have the same value (of type size_t) both places it
occurs, so this is still casting an integer constant expression with
value 0 to void *, and is no less a valid definition of NULL if "int"
means double than if "int" means int.
Can an implementation legally define macros that rely on int really
meaning int? I think your first example is valid, and in this case
Dan's #define will break code that uses it.
Alternately, either the programmer isn't allowed to define preprocessor
macros with the same names as type names (perhaps all keywords?), or the
implementation really should do something like "typedef void *__voidptr"
and use a cast to __voidptr in NULL (and do something similar for other
type names it uses in macros) instead of using type names that the
programmer is allowed to mangle.
dave
-- Dave Vandervies dj3vande@csclub.uwaterloo.ca Uh-huh. And a criticism of computers is that they manipulate numbers without feeling, and a criticism of humans is that they are bipeds that eat and make little bipeds. --Peter Seebach in comp.lang.c
- Next message: Christopher Benson-Manica: "Re: Embedded Vs Java"
- Previous message: John Bode: "Re: How to call appropriate functions?"
- In reply to: Arthur J. O'Dwyer: "Re: Obfuscation devices (was Name Space Pollution: using macros ...)"
- Next in thread: Jun Woong: "Re: Obfuscation devices (was Name Space Pollution: using macros ...)"
- Reply: Jun Woong: "Re: Obfuscation devices (was Name Space Pollution: using macros ...)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|