Static but never defined?

This is a discussion on Static but never defined? within the C Programming forums, part of the General Programming Boards category; When building I get a warning like this: `MyReadProc' declared `static' but never defined Can someone please help me with ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    63

    Talking Static but never defined?

    When building I get a warning like this:

    `MyReadProc' declared `static' but never defined

    Can someone please help me with this?
    You cantīt teach an old dog new tricks.

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    44
    Without seeing the code, it's very difficult to say what's wrong. Even so, here's a guess:

    You have declared a function MyReadProc but not defined it...

    In other words, you have something like this:

    Code:
    static void MyReadProc();
    somewhere, without ever defining the function MyReadProc.

    The reason why you don't get this for normal non-static functions is because static functions are only accessible from within the execution unit (think file...) in which they are defined/declared. Non-static functions can be declared but not defined and the linker tries to resolve it later. Static functions can only be used in the same execution unit in which they were defined/declared and so the linker won't try and resolve them later... hence the warning.

    If you've done something like declared MyReadProc as static in a header file and then included that header file, then you'll get the kind of error. Declaring it static means that you cannot link to it outside of the execution unit in which it was defined, so it cannot be called by anyone outside of the file. Adding it to a header file is erroneous. If you do want to be able to call it from other execution units, then you need to make it a non-static function.

    Static is one of those things in C which means different things in different contexts. A static variable is something completely different to a static function.

    I hope that explains your warning...!

    Ian Woods

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    63
    Originally posted by hairyian
    Without seeing the code, it's very difficult to say what's wrong. Even so, here's a guess:

    You have declared a function MyReadProc but not defined it...

    In other words, you have something like this:

    Code:
    static void MyReadProc();
    somewhere, without ever defining the function MyReadProc.

    The reason why you don't get this for normal non-static functions is because static functions are only accessible from within the execution unit (think file...) in which they are defined/declared. Non-static functions can be declared but not defined and the linker tries to resolve it later. Static functions can only be used in the same execution unit in which they were defined/declared and so the linker won't try and resolve them later... hence the warning.

    If you've done something like declared MyReadProc as static in a header file and then included that header file, then you'll get the kind of error. Declaring it static means that you cannot link to it outside of the execution unit in which it was defined, so it cannot be called by anyone outside of the file. Adding it to a header file is erroneous. If you do want to be able to call it from other execution units, then you need to make it a non-static function.

    Static is one of those things in C which means different things in different contexts. A static variable is something completely different to a static function.

    I hope that explains your warning...!

    Ian Woods
    I will tell you what I am trying to do.

    I have a file called midithruCategory.m where the static function is located like this:

    static void MyReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
    {
    some code...
    }

    I also have a file called initvintageeightCategory.m that looks like this:

    // Create client and port
    MIDIClientRef client = NULL;
    MIDIClientCreate(CFSTR("VintageEight"), NULL, NULL, &client);
    MIDIPortRef inPort = NULL;
    MIDIInputPortCreate(client, CFSTR("Input port"), MyReadProc, NULL, &inPort);
    MIDIOutputPortCreate(client, CFSTR("Output port"), &gOutPort);

    The thing I want to do here is now a lot clearer and maybe you can tell me what I must do to make this work?

    I also have .h files with the same names as the .m files
    You cantīt teach an old dog new tricks.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    63

    Cool

    Originally posted by electrolove
    I will tell you what I am trying to do.

    I have a file called midithruCategory.m where the static function is located like this:

    static void MyReadProc(const MIDIPacketList *pktlist, void *refCon, void *connRefCon)
    {
    some code...
    }

    I also have a file called initvintageeightCategory.m that looks like this:

    // Create client and port
    MIDIClientRef client = NULL;
    MIDIClientCreate(CFSTR("VintageEight"), NULL, NULL, &client);
    MIDIPortRef inPort = NULL;
    MIDIInputPortCreate(client, CFSTR("Input port"), MyReadProc, NULL, &inPort);
    MIDIOutputPortCreate(client, CFSTR("Output port"), &gOutPort);

    The thing I want to do here is now a lot clearer and maybe you can tell me what I must do to make this work?

    I also have .h files with the same names as the .m files
    Hold your horses, I think I got it now :-)
    You cantīt teach an old dog new tricks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 04:42 PM
  2. Linking errors with static var
    By Elysia in forum C++ Programming
    Replies: 8
    Last Post: 10-27-2007, 05:24 PM
  3. Static variables and functions problem in a class
    By earth_angel in forum C++ Programming
    Replies: 16
    Last Post: 09-15-2005, 12:08 PM
  4. Private Static class members
    By earth_angel in forum C++ Programming
    Replies: 13
    Last Post: 08-29-2005, 06:37 AM
  5. how to set the background colour of a static box?
    By Cobras2 in forum Windows Programming
    Replies: 2
    Last Post: 08-01-2002, 04:57 PM

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