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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lovecreatesbea...@gmail.com

    #1

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

    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(usene t, "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(usene t, "clc") = "clc";
    /*more consts...*/

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

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

    lovecreatesbea. ..@gmail.com 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(usene t, "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(usene t, "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@sun .com

    Comment

    • lovecreatesbea...@gmail.com

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

      On Feb 28, 11:35 pm, Eric Sosman <Eric.Sos...@su n.comwrote:
      lovecreatesbea. ..@gmail.com 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(usene t, "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(usene t, "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.

      Comment

      Working...