declaration issues

This is a discussion on declaration issues within the C Programming forums, part of the General Programming Boards category; Hi I have just come across an issue that i am just not able to understand.. i have declared a ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    32

    declaration issues

    Hi

    I have just come across an issue that i am just not able to understand..
    i have declared a structure in one of .c files ..
    e.g.

    Code:
    struct fun {
        char var1;
        int var 2;
        struct fun *next 
    };
    now what i have done is i have made a header file and put a typedef like:

    Code:
    typedef struct fun morefun
    and GOD KNOWS how the header file is able to know that the structure has been defined in the other file..and code is compiling with not even a single warning..

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What does the code that uses morefun look like? If it's only using morefun as a pointer, and never accessing it's content, then you only need to tell the compiler that it's "some sort of struct called fun", which is what you have done.

    The code will not compile if it's accessing members of a struct that hasn't been declared. No doubt about this.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. Errors with including winsock 2 lib
    By gamingdl'er in forum C++ Programming
    Replies: 3
    Last Post: 12-05-2005, 07:13 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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