Thread: Connecting and dealing with source files

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    I know what you mean. Yet, I wouldn't call it a definition, because it doesn't... quite qualify for that in my opinion. Perhaps they could have worded it different?
    The first is after all called a forward declaration. Perhaps a forward declaration could be made distinct from declaration.
    Oh well.
    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.

  2. #17
    Registered User
    Join Date
    Aug 2009
    Posts
    24
    I have it working now I put the extern line in the header and the second line in only one source file. Thanks

    These structs come from a library. When the compiler was suggesting I was defining them, I just though I was creating an instance of them (or actually only a pointer to them). I guess that must amount to having a new struct, thus it has been defined?

    P.S.
    Quote Originally Posted by tabstop View Post
    So if this is a conscious design decision (i.e., you are doing this for a good reason, and not "I don't know any better")
    My 'good' reason is I'm attempting to organise things in a C++ way so I learn it 'right', only I'm obviously not yet.
    Last edited by alanb; 08-27-2009 at 05:55 PM.

  3. #18
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Describing the layout of your struct is called defining the struct.
    Creating an instance of the struct would be ... well, defining a variable of the type of your struct.
    Also, say, you say organize in a C++ way, but you are posting in C?
    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.

  4. #19
    Registered User
    Join Date
    Aug 2009
    Posts
    24
    Quote Originally Posted by Elysia View Post
    Creating an instance of the struct would be ... well, defining a variable of the type of your struct.
    That's what I thought?
    Also, say, you say organize in a C++ way, but you are posting in C?
    I figured since this question was not C++ specific.....I'll get the hang of it.

  5. #20
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Multiple source files isn't specific to C either, so...
    Plus C++ allows something else that's specific to this topic that C doesn't, namely constants.
    Constants in C are usually #defines, but in C++, they can be different.

    There is something called a constant expression. A constant expression is basically something that the compiler can understand at compile time, such as a constant (integer, such as 10 or even 20 / 2, etc).
    If we add const to a variable and initialize it with a constant expression, then the variable itself becomes a constant expression. That means it isn't treated as a variable, which in turn means that we can put it in a header, like so:

    const int n = 50;

    And it will work.
    Doesn't work in C.
    Last edited by Elysia; 08-28-2009 at 11:15 AM.
    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