[C] #define - unexpected Results

From: Paulie (p1150gs_at_yahoonospam.co.uk)
Date: 11/28/04


Date: Sun, 28 Nov 2004 22:03:13 -0000

Hi all.

I just came across something that I think is weird in my program and
wondered if I was misunderstanding it or the compiler was at fault. Cut
down to the basics the program goes like this:

void foo(unsigned char);
#define NINE 9

int main (void)
{
printf("%x", NINE); // Prints out 9
foo(NINE);
blah blah
}

void foo(unsigned char a)
{
printf("%x", a);
}

I would expect the program to print out 9 as the hex value, but it actually
prints out F9 (I am working on a mainframe system using EBCDIC notation so
F9 is character '9'). Am I missing the point or is there something curious
going on that needs further investigation.

I tried it out on my PC compiler and got 9 both times (as I expected).

Thanks, Paulie



Relevant Pages

  • Re: Micro-C -- Help monitoring a switch on 8051
    ... > pushed" should be displayed in the LCD. ... Hopefully, this is a standard compliant C compiler, otherwise you won't ... char ScanKeypad(void); ...
    (comp.lang.c)
  • inherited member function not seen
    ... However, when I try to compile the example below, the compiler claims ... initializing argument 1 of 'void B::push_back(const char *)' ... 'push_back' function (based on its argument type: int) to ...
    (comp.lang.cpp)
  • Re: inline vs macro
    ... In other words, if you use it right, void * is fine, and if you don't, it ... But surely the whole point of type safety is that the compiler should yell ... char c = 'A'; ...
    (comp.lang.c)
  • Re: large files: when ubiquitous?
    ... > optimizations performed by the compiler. ... > pointer to a float, and another pointer to a long, the ... void* is a contractural promise that it's 4-aligned. ... If we pass char* instead to f, then we would be implictly saying that we ...
    (comp.os.linux.development.system)
  • Re: [C] #define - unexpected Results
    ... > wondered if I was misunderstanding it or the compiler was at fault. ... > void foo(unsigned char a) { ... (which is expecting an unsigned int, ... didn't compile because of the "blah blah" lines. ...
    (alt.comp.lang.learn.c-cpp)