redefinition of typedef

前端 未结 7 984
北荒
北荒 2020-12-15 05:54

I am possibly doing this incorrectly and this is much a question about why it works in one compiler and not the other.

I have a large C application, and I am

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-15 06:08

    As others have already stated, you cannot redefine types in C. This error mostly indicates that there might be looped includes or other logic flaw. To avoid this, the best practice is to lock include files i.e.

    #ifndef __HEADER_H__
    #define __HEADER_H__
    
    // Your code goes here
    
    #endif
    

    This way unnecessary includes will be omitted by this lock.
    In your example you would need to include B in A and A in C. Including B in C would have no effect and would satisfy the compiler

提交回复
热议问题