/*this meaningful?*/ #define CONST_INT(name, value) extern const intname

Discussion in 'C Programming' started by lovecreatesbea...@gmail.com, Feb 28, 2008.

  1. Guest

    Similar macros like "CONST_INT" in product code. Does it deserve this?
    Thank you for your time.


    /* a.h ***********************************************************/
    #ifndef CONST_INT
    #define CONST_INT(name, value) extern const int name
    #endif
    #ifndef CONST_DBL
    #define CONST_DBL(name, value) extern const double name
    #endif
    #ifndef CONST_STR
    #define CONST_STR(name, value) extern const char *name
    #endif
    /*more defs...*/


    CONST_INT(age, 18);
    CONST_DBL(len, 19.9);
    CONST_STR(usenet, "clc");
    /*more consts...*/


    /* a.c ***********************************************************/
    #include <stdio.h>
    #include "a.h"

    CONST_INT(age, 18) = 18;
    CONST_DBL(len, 19.9) = 19.9;
    CONST_STR(usenet, "clc") = "clc";
    /*more consts...*/

    int a(void){
    printf("%d, %f, %s\n", age, len, usenet);
    /*more stuff*/
    return 0;
    }
     
    , Feb 28, 2008
    #1
    1. Advertising

  2. Eric Sosman Guest

    Re: /*this meaningful?*/ #define CONST_INT(name, value) extern constint name

    wrote:
    > Similar macros like "CONST_INT" in product code. Does it deserve this?
    > Thank you for your time.
    >
    >
    > /* a.h ***********************************************************/
    > #ifndef CONST_INT
    > #define CONST_INT(name, value) extern const int name
    > #endif
    > #ifndef CONST_DBL
    > #define CONST_DBL(name, value) extern const double name
    > #endif
    > #ifndef CONST_STR
    > #define CONST_STR(name, value) extern const char *name
    > #endif
    > /*more defs...*/
    >
    >
    > CONST_INT(age, 18);
    > CONST_DBL(len, 19.9);
    > CONST_STR(usenet, "clc");
    > /*more consts...*/
    >
    >
    > /* a.c ***********************************************************/
    > #include <stdio.h>
    > #include "a.h"
    >
    > CONST_INT(age, 18) = 18;
    > CONST_DBL(len, 19.9) = 19.9;
    > CONST_STR(usenet, "clc") = "clc";
    > /*more consts...*/
    >
    > int a(void){
    > printf("%d, %f, %s\n", age, len, usenet);
    > /*more stuff*/
    > return 0;
    > }


    Looks silly: Why specify each value twice? I suspect
    you've overlooked a set of alternative definitions of the
    macros, that look something like

    CONST_INT(name value) const int name = (value)

    .... the idea being to put `CONST_INT(age, 18);' in a lot
    of files (probably by way of #include), where most use
    the first CONST_INT definition and exactly one uses the
    second.

    --
     
    Eric Sosman, Feb 28, 2008
    #2
    1. Advertising

  3. Guest

    Re: /*this meaningful?*/ #define CONST_INT(name, value) extern constint name

    On Feb 28, 11:35 pm, Eric Sosman <> wrote:
    > wrote:
    > > Similar macros like "CONST_INT" in product code. Does it deserve this?
    > > Thank you for your time.

    >
    > > /* a.h ***********************************************************/
    > > #ifndef CONST_INT
    > > #define CONST_INT(name, value) extern const int name
    > > #endif
    > > #ifndef CONST_DBL
    > > #define CONST_DBL(name, value) extern const double name
    > > #endif
    > > #ifndef CONST_STR
    > > #define CONST_STR(name, value) extern const char *name
    > > #endif
    > > /*more defs...*/

    >
    > > CONST_INT(age, 18);
    > > CONST_DBL(len, 19.9);
    > > CONST_STR(usenet, "clc");
    > > /*more consts...*/

    >
    > > /* a.c ***********************************************************/
    > > #include <stdio.h>
    > > #include "a.h"

    >
    > > CONST_INT(age, 18) = 18;
    > > CONST_DBL(len, 19.9) = 19.9;
    > > CONST_STR(usenet, "clc") = "clc";
    > > /*more consts...*/

    >
    > > int a(void){
    > > printf("%d, %f, %s\n", age, len, usenet);
    > > /*more stuff*/
    > > return 0;
    > > }

    >
    > Looks silly: Why specify each value twice? I suspect
    > you've overlooked a set of alternative definitions of the
    > macros, that look something like
    >
    > CONST_INT(name value) const int name = (value)


    I've paied special attention on this. They just don't have the "value"
    arg in the macro bodies. I guess the literal values in the
    declarations in the header are just like comments.
     
    , Feb 28, 2008
    #3
  4. Thad Smith Guest

    Re: /*this meaningful?*/ #define CONST_INT(name, value) extern constint name

    wrote:
    > On Feb 28, 11:35 pm, Eric Sosman <> wrote:
    >> wrote:
    >>> Similar macros like "CONST_INT" in product code. Does it deserve this?
    >>> Thank you for your time.
    >>> /* a.h ***********************************************************/
    >>> #ifndef CONST_INT
    >>> #define CONST_INT(name, value) extern const int name
    >>> #endif
    >>> #ifndef CONST_DBL
    >>> #define CONST_DBL(name, value) extern const double name
    >>> #endif
    >>> #ifndef CONST_STR
    >>> #define CONST_STR(name, value) extern const char *name
    >>> #endif
    >>> /*more defs...*/
    >>> CONST_INT(age, 18);
    >>> CONST_DBL(len, 19.9);
    >>> CONST_STR(usenet, "clc");
    >>> /*more consts...*/
    >>> /* a.c ***********************************************************/
    >>> #include <stdio.h>
    >>> #include "a.h"
    >>> CONST_INT(age, 18) = 18;
    >>> CONST_DBL(len, 19.9) = 19.9;
    >>> CONST_STR(usenet, "clc") = "clc";
    >>> /*more consts...*/
    >>> int a(void){
    >>> printf("%d, %f, %s\n", age, len, usenet);
    >>> /*more stuff*/
    >>> return 0;
    >>> }

    >> Looks silly: Why specify each value twice? I suspect
    >> you've overlooked a set of alternative definitions of the
    >> macros, that look something like
    >>
    >> CONST_INT(name value) const int name = (value)

    >
    > I've paied special attention on this. They just don't have the "value"
    > arg in the macro bodies. I guess the literal values in the
    > declarations in the header are just like comments.


    What has probably happened is that one programmer has written the header
    file and also written something like

    #define CONST_INT(name,value) const int name = value;
    /* ... define other CONST_* macros */
    #include "a.h"

    in one of the source files, which is a reasonable way to initialize the
    constant variables in one module and reference in several.

    /Another/ programmer, not understanding the design, must have misapplied
    this technique to another piece of code, resulting in the mishmash you are
    looking at.

    --
    Thad
     
    Thad Smith, Feb 29, 2008
    #4
    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. walala
    Replies:
    1
    Views:
    1,257
    Mike Treseler
    Aug 11, 2003
  2. Joshua Ellul
    Replies:
    0
    Views:
    343
    Joshua Ellul
    Feb 15, 2004
  3. Thomas Matthews
    Replies:
    5
    Views:
    2,547
    tom_usenet
    Aug 2, 2004
  4. Khalid Sheikh
    Replies:
    1
    Views:
    424
    Dennis Lee Bieber
    Jul 19, 2003
  5. Javier
    Replies:
    2
    Views:
    619
    James Kanze
    Sep 4, 2007
Loading...

Share This Page