Thread: typedef problem

  1. #1
    Registered User
    Join Date
    Dec 2007

    typedef problem

    Hello, I have 3 header files and 1 .c file.

    The .c file #includes both header files.

    In the 2 header files, there are extern definitions of of a struct:


    #include "types.h"
    extern struct a
         mytype a;
    } myStructA;

    #include "types.h"
    extern struct b
          mytype b;
    } myStructB
    typedef int mytype;

    #include "header1.h"
    #include "header2.h"
    struct myStructA;
    struct myStructB;
    int main()
    My issue is that gcc keeps complaining about a redefinition of typedef mytype. I understand what this means since I #include types.h in both headers. I need to do this since both headers use mytype in their stucts. Is there any way around this?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Use inclusion guards.

  3. #3
    a newbie :p
    Join Date
    Aug 2008
    Zurich, Switzerland, Switzerland
    if it is microsoft, you can use
    #pragma once

  4. #4
    Join Date
    Oct 2007
    That pragma does not work very well for inclusion guards.
    And the struct shouldn't be "extern" either. It's a declaration.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  3. typedef problem
    By dr$brown in forum C Programming
    Replies: 6
    Last Post: 12-25-2004, 11:27 AM
  4. build errors migrated from dx9b to dx9c sdk
    By reanimated in forum Game Programming
    Replies: 4
    Last Post: 12-17-2004, 06:35 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM