#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    208
    Rep Power
    13

    Why does the routine called without the underscores


    Hi,

    I saw some proC code. The function was declared as,

    Code:
    lookup some thing(void);
    Then it was called in a routine,

    Code:
    void process_this(void)
    {
       lookup some thing();
    }
    But the function definition is,
    Code:
    void lookup_some_thing(void)
    {
        return;
    }
    Why does the function name in the definition have the underscores?
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,184
    Rep Power
    2222
    Do you mean Pro*C, and embedded SQL compiler? (http://en.wikipedia.org/wiki/Pro*C)

    I can tell you that in C this,
    lookup some thing(void);
    , is not a valid declaration. But since the Pro*C language is itself not C, but rather gets run through a pre-processor to convert it to C, I would have to conclude that that declaration is Pro*C and not C. As the cited article says:
    Originally Posted by Wikipedia
    During compilation, the embedded SQL statements are interpreted by a precompiler and replaced by C or C++ function calls to their respective SQL library. The output from the Pro*C precompiler is standard C or C++ code that is then compiled by any one of several C or C++ compilers into an executable.
    If your "proC" is something entirely different, then you will need to provide us with some information about it.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    208
    Rep Power
    13
    dwise1_aol,

    You're right. It is Pro*C. But I still don't understand why it works like that. Why aren't they consistent?

    defs.h
    Code:
    void lookup some thing(void)
    foo.pc
    Code:
    #include <defs.h>
    void process_this(void)
    {
       lookup some thing();
    }
    
    void lookup_some_thing(void)
    {
        return;
    }
    Last edited by soap; August 22nd, 2013 at 02:57 PM.
  6. #4
  7. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,184
    Rep Power
    2222
    C syntax does not allow something like: void lookup some thing(void)
    It's as simple as that.

    C is not FORTRAN -- FORTRAN allows spaces within identifiers, but C and just about every other language does not. Spaces are white space. They act as delimiters between identifiers. They terminate identifiers. When you parse an identifer, hitting a space ends that parse. So lookup some thing would not be a single identifier, a function name, but rather three separate identifiers in an expression whose syntax is invalid in C.

    Yet apparently embedding spaces within an identifier is allowed in Pro*C. So the pre-processor that converts Pro*C into valid C substitutes underscores for the embedded spaces to turn those Pro*C identifiers into C identifiers.

    The bottom line is that
    Code:
    void lookup some thing(void)
    is not C, whereas
    Code:
    void lookup_some_thing(void)
    is C. Just as "Dies Computer läuft nicht." is not English whereas "This computer doesn't work." is English. How much more can we explain the obvious?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    208
    Rep Power
    13
    I got it. Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo