A #define that I´m not used to

Discussion in 'C Programming' started by Morris Dovey, Feb 12, 2008.

  1. Morris Dovey

    Morris Dovey Guest

    "" wrote:
    >
    > Hello all,


    Bom dia!

    > Could someone have the generosity of explaining me what this #defines
    > define?
    >
    > #define YPAD_PROTOTYPE(PAD) extern void PAD ();


    Expands to produce a prototype statement. For example:

    YPAD_PROTOTYPE(my_function)

    produces

    extern void my_function ();

    > #define YPAD_FUNCTION(PAD) extern void PAD (VarP) xPrsNode VarP;


    Here

    YPAD_FUNCTION(my_function)

    Expands to produce

    extern void my_function (VarP) xPrsNode VarP

    which is almost certainly expanded further by other macro
    definitions.

    --
    Morris Dovey
    DeSoto Solar
    DeSoto, Iowa USA
    http://www.iedu.com/DeSoto
    Morris Dovey, Feb 12, 2008
    #1
    1. Advertising

  2. Morris Dovey

    Guest

    Hello all,

    Could someone have the generosity of explaining me what this #defines
    define?

    #define YPAD_PROTOTYPE(PAD) extern void PAD ();
    #define YPAD_FUNCTION(PAD) extern void PAD (VarP) xPrsNode VarP;
    #define YPRD_PROTOTYPE(PAD) extern int PAD ();
    #define YPRD_FUNCTION(PAD) extern int PAD (VarP) xPrsNode VarP;


    Thanks a lot,

    André LS Meirelles
    , Feb 12, 2008
    #2
    1. Advertising

  3. Morris Dovey

    Guest

    On 12 fev, 17:47, Morris Dovey <> wrote:
    > "" wrote:
    >
    > > Hello all,

    >
    > Bom dia!


    :)

    You got it right and clear portuguese!

    >
    > > Could someone have the generosity of explaining me what this #defines
    > > define?

    >
    > > #define YPAD_PROTOTYPE(PAD) extern void PAD ();

    >
    > Expands to produce a prototype statement. For example:
    >
    > YPAD_PROTOTYPE(my_function)
    >
    > produces
    >
    > extern void my_function ();
    >
    > > #define YPAD_FUNCTION(PAD) extern void PAD (VarP) xPrsNode VarP;

    >
    > Here
    >
    > YPAD_FUNCTION(my_function)
    >
    > Expands to produce
    >
    > extern void my_function (VarP) xPrsNode VarP
    >
    > which is almost certainly expanded further by other macro
    > definitions.


    Yeah, that makes a lot of sense, thanks!!

    >
    > --
    > Morris Dovey
    > DeSoto Solar
    > DeSoto, Iowa USAhttp://www.iedu.com/DeSoto
    , Feb 12, 2008
    #3
  4. Morris Dovey

    Eric Sosman Guest

    Morris Dovey wrote:
    > "" wrote:
    >> Hello all,

    >
    > Bom dia!
    >
    >> Could someone have the generosity of explaining me what this #defines
    >> define?
    >>
    >> #define YPAD_PROTOTYPE(PAD) extern void PAD ();

    >
    > Expands to produce a prototype statement. For example:
    >
    > YPAD_PROTOTYPE(my_function)
    >
    > produces
    >
    > extern void my_function ();


    Yes, but this is not "a prototype statement." It is a
    function declaration with no prototype.

    >> #define YPAD_FUNCTION(PAD) extern void PAD (VarP) xPrsNode VarP;

    >
    > Here
    >
    > YPAD_FUNCTION(my_function)
    >
    > Expands to produce
    >
    > extern void my_function (VarP) xPrsNode VarP


    No, there is also a semicolon `;' in the macro expansion.

    > which is almost certainly expanded further by other macro
    > definitions.


    It may be further expanded, but I wouldn't say "almost
    certainly." It looks very much like the start of an old-
    style (pre-prototype) function definition, and is probably
    followed by a `{}'-enclosed block that is the function body.

    The `extern' is unusual, but harmless.

    --
    Eric Sosman, Feb 12, 2008
    #4
  5. Morris Dovey

    Guest

    On 12 fev, 18:58, Eric Sosman <> wrote:
    > Morris Dovey wrote:
    > > "" wrote:
    > >> Hello all,

    >
    > > Bom dia!

    >
    > >> Could someone have the generosity of explaining me what this #defines
    > >> define?

    >
    > >> #define YPAD_PROTOTYPE(PAD) extern void PAD ();

    >
    > > Expands to produce a prototype statement. For example:

    >
    > > YPAD_PROTOTYPE(my_function)

    >
    > > produces

    >
    > > extern void my_function ();

    >
    > Yes, but this is not "a prototype statement." It is a
    > function declaration with no prototype.
    >
    > >> #define YPAD_FUNCTION(PAD) extern void PAD (VarP) xPrsNode VarP;

    >
    > > Here

    >
    > > YPAD_FUNCTION(my_function)

    >
    > > Expands to produce

    >
    > > extern void my_function (VarP) xPrsNode VarP

    >
    > No, there is also a semicolon `;' in the macro expansion.
    >
    > > which is almost certainly expanded further by other macro
    > > definitions.

    >
    > It may be further expanded, but I wouldn't say "almost
    > certainly." It looks very much like the start of an old-
    > style (pre-prototype) function definition, and is probably
    > followed by a `{}'-enclosed block that is the function body.
    >


    That´s the problem, I don´t know wich #define is beeing expanded. The
    function has a body (a big one in fact). The definition starts like
    this:

    YPAD_FUNCTION(yPAD_mmc)


    > The `extern' is unusual, but harmless.
    >
    > --
    >
    , Feb 12, 2008
    #5
  6. Morris Dovey

    Eric Sosman Guest

    wrote:
    > [...]
    > That´s the problem, I don´t know wich #define is beeing expanded. The
    > function has a body (a big one in fact). The definition starts like
    > this:
    >
    > YPAD_FUNCTION(yPAD_mmc)


    The expansion is

    extern void yPAD_mmc (VarP) xPrsNode VarP;

    Have you, perhaps, been confused by the similarity of
    the macro names? They differ by just one character, buried
    in the middle and topologically similar:

    #define YPAD_PROTOTYPE ...
    #define YPRD_PROTOTYPE ...
    ^

    #define YPAD_FUNCTION ...
    #define YPRD_FUNCTION ...
    ^

    --
    Eric Sosman, Feb 12, 2008
    #6
  7. Morris Dovey

    Kaz Kylheku Guest

    On Feb 12, 11:47 am, Morris Dovey <> wrote:
    > Here
    >
    >    YPAD_FUNCTION(my_function)
    >
    > Expands to produce
    >
    >    extern void my_function (VarP) xPrsNode VarP


    Also, there is a semicolon.

    > which is almost certainly expanded further by other macro
    > definitions.


    I would guess that likely works like this:

    YPAD_FUNCTION(my_function)
    {
    /* body that references VarP of type xPrsNode
    }

    My guess is that the YPAD macros are conditionally defined to switch
    between ANSI declarations and old-style.
    Kaz Kylheku, Feb 13, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. theotyflos
    Replies:
    3
    Views:
    464
    Thomas Matthews
    Feb 19, 2004
  2. robin liu
    Replies:
    3
    Views:
    821
    Robin Liu
    Apr 21, 2006
  3. giuliano
    Replies:
    13
    Views:
    419
    CBFalconer
    Jan 16, 2007
  4. Replies:
    2
    Views:
    429
    Aleksey Loginov
    Nov 7, 2005
  5. Brian Takita

    #define _ and #define __

    Brian Takita, Jan 23, 2006, in forum: Ruby
    Replies:
    0
    Views:
    458
    Brian Takita
    Jan 23, 2006
Loading...

Share This Page