Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > /*this meaningful?*/ #define CONST_INT(name, value) extern const intname

Reply
Thread Tools

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

 
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      02-28-2008
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, 1;
CONST_DBL(len, 19.9);
CONST_STR(usenet, "clc");
/*more consts...*/


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

CONST_INT(age, 1 = 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;
}
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      02-28-2008
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, 1;
> CONST_DBL(len, 19.9);
> CONST_STR(usenet, "clc");
> /*more consts...*/
>
>
> /* a.c ************************************************** *********/
> #include <stdio.h>
> #include "a.h"
>
> CONST_INT(age, 1 = 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, 1;' in a lot
of files (probably by way of #include), where most use
the first CONST_INT definition and exactly one uses the
second.

--

 
Reply With Quote
 
 
 
 
lovecreatesbea...@gmail.com
Guest
Posts: n/a
 
      02-28-2008
On Feb 28, 11:35 pm, Eric Sosman <Eric.Sos...@sun.com> wrote:
> 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, 1;
> > CONST_DBL(len, 19.9);
> > CONST_STR(usenet, "clc");
> > /*more consts...*/

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

>
> > CONST_INT(age, 1 = 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.
 
Reply With Quote
 
Thad Smith
Guest
Posts: n/a
 
      02-29-2008
lovecreatesbea...@gmail.com wrote:
> On Feb 28, 11:35 pm, Eric Sosman <Eric.Sos...@sun.com> wrote:
>> 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, 1;
>>> CONST_DBL(len, 19.9);
>>> CONST_STR(usenet, "clc");
>>> /*more consts...*/
>>> /* a.c ************************************************** *********/
>>> #include <stdio.h>
>>> #include "a.h"
>>> CONST_INT(age, 1 = 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference of extern short *x and extern short x[]? Andre C Programming 5 07-17-2012 07:38 PM
is const necessary in eg int compar(const void *, const void *) lovecreatesbeauty@gmail.c0m C Programming 26 11-10-2008 09:47 PM
const vector<A> vs vector<const A> vs const vector<const A> Javier C++ 2 09-04-2007 08:46 PM
Casting int'** to 'const int * const * const' dosn't work, why? Jonas.Holmsten@gmail.com C Programming 11 07-01-2007 06:16 PM
extern const char * vs. extern const char []http://tinyurl.com/47e3k Thomas Matthews C++ 5 08-02-2004 10:36 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57