defining new boolean type causes redefinition error in visual c

i define a new boolean type using typedef in my Visual C program:
[code]#ifndef TRUE
#define FALSE 0
#define TRUE 1
#endif

typedef int boolean;[/code]
but i get the error:
"error C2371: 'boolean' : redefinition; different basic types
c:program filesmicrosoft visual studiovc98include
pcndr.h(173) : see declaration of 'boolean'"

how can i use my declaration without changing the rpcndr.h declaration?
my functions will use my declaration, rpcndr.h's functions will use his declarations.

Comments

  • [code]
    #ifndef TRUE
    #define FALSE 0
    #define TRUE 1
    typedef int boolean;
    #endif
    [/code]

    This is the first thing to do.
    The other is to ask yourself if you will ever use other compiler than VC to compile your program. If not, use VC's boolean.



  • [b][red]This message was edited by Lundin at 2005-8-14 13:20:48[/red][/b][hr]
    : [code]
    : #ifndef TRUE
    : #define FALSE 0
    : #define TRUE 1
    : typedef int boolean;
    : #endif
    : [/code]
    :
    : This is the first thing to do.
    : The other is to ask yourself if you will ever use other compiler than VC to compile your program. If not, use VC's boolean.
    :
    :


    Or more detailed:

    [code]
    #ifndef TRUE
    #ifndef boolean
    typedef enum {FALSE, TRUE} boolean;
    #endif
    #endif
    [/code]

    But seriously, any Windows compiler will use windows.h where BOOL, TRUE and FALSE are defined, so why don't use that one?

  • thank you for your reply.
    yes, i will use other compiler than VC to compile my program.

    when i use #ifndef TRUE, if TRUE is defined it will use the previous definition?
  • : thank you for your reply.
    : yes, i will use other compiler than VC to compile my program.
    :
    : when i use #ifndef TRUE, if TRUE is defined it will use the previous definition?
    :

    Yes.

    Easiest solution is #include
    Works on all Win compilers.
  • Sorry to disturb this thread, but what you are saying is that "boolean" is a native type ONLY to VC?
    So if I'd use another compiler, I couldn't use the standard boolean type anymore?

    Greets...
    Richard

  • : Sorry to disturb this thread, but what you are saying is that "boolean" is a native type ONLY to VC?
    : So if I'd use another compiler, I couldn't use the standard boolean type anymore?
    :
    : Greets...
    : Richard
    :
    :
    The standard is libc, it is why you should always check the environement at compile time to know what features are present and which aren't
  • : Sorry to disturb this thread, but what you are saying is that "boolean" is a native type ONLY to VC?
    : So if I'd use another compiler, I couldn't use the standard boolean type anymore?
    :
    : Greets...
    : Richard
    :
    :

    As long as we are talking C, there is no standard boolean type.
    (They introduced it in C99 but almost no compiler has implemented that)
    The closest you get, as long as you stick to Windows, it the type BOOL is windows.h.
  • but i would like to compile my code on Linux and on Windows,
    for that i have to use my own bool type. no?


    : : Sorry to disturb this thread, but what you are saying is that "boolean" is a native type ONLY to VC?
    : : So if I'd use another compiler, I couldn't use the standard boolean type anymore?
    : :
    : : Greets...
    : : Richard
    : :
    : :
    :
    : As long as we are talking C, there is no standard boolean type.
    : (They introduced it in C99 but almost no compiler has implemented that)
    : The closest you get, as long as you stick to Windows, it the type BOOL is windows.h.
    :

  • : : Sorry to disturb this thread, but what you are saying is that "boolean" is a native type ONLY to VC?
    : : So if I'd use another compiler, I couldn't use the standard boolean type anymore?
    : :
    : : Greets...
    : : Richard
    : :
    : :
    :
    : As long as we are talking C, there is no standard boolean type.
    : (They introduced it in C99 but almost no compiler has implemented that)
    : The closest you get, as long as you stick to Windows, it the type BOOL is windows.h.
    :

    Or [blue]bool[/blue] in C++ to be used with [blue]true[/blue] and [blue]false[/blue]



    [italic][blue]To understand recursive, first you need to understand recursive[/blue][/italic]

  • : but i would like to compile my code on Linux and on Windows,
    : for that i have to use my own bool type. no?

    Yes, though you might have to check enviroment variables to detect which OS you are using. The problem is that you might not detect the bool type with pre-processor #ifdef, sence it might be defined with typedef enum.
    Safest way for your own bool type is to come up with a name that no compiler uses.

    Note that all those problems only exists in C. In C++, use the standard type "bool".

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories