#define problem in C

This is a discussion on #define problem in C within the C Programming forums, part of the General Programming Boards category; Code: struct s { int i; }; typedef struct s service; #ifdef __SERVICE__ #define FOO 2 #endif main() { printf("%d",FOO); ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    2

    #define problem in C

    Code:
    struct s { int i; };
    typedef struct s service;
    
    #ifdef __SERVICE__
    #define FOO 2
    #endif
    
    main()
    {
    printf("%d",FOO);
    }
    Why the above code does not print the value of FOO, saying that it was not declared?
    Why #ifdef condition evaluates to false though 'service' was defined with typedef earlier?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,485
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. stdio.h?
    By kiros88 in forum C Programming
    Replies: 5
    Last Post: 05-21-2010, 07:09 PM
  2. Changing flags from a DLL?
    By RobotGymnast in forum C++ Programming
    Replies: 17
    Last Post: 10-27-2008, 01:34 PM
  3. size of an integer pointer
    By onebrother in forum C Programming
    Replies: 5
    Last Post: 07-09-2008, 11:49 AM
  4. whats wrong here
    By sreetvert83 in forum C++ Programming
    Replies: 15
    Last Post: 09-21-2005, 10:05 AM
  5. Help getting multiple keypresses in a DOS compiler
    By Nongan in forum Game Programming
    Replies: 2
    Last Post: 04-01-2005, 09:07 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21