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

L

lovecreatesbea...

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;
}
 
E

Eric Sosman

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.
 
L

lovecreatesbea...

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.
 
T

Thad Smith

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top