🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.help
Article #51812

Passing string constant with -D

#51812
From: Chris Atkins
Date: Fri, 02 Apr 1993 17:25
55 lines
1475 bytes
I am trying to use the -D argument to pass a string constant into my code at
compile time.  I invoke gcc with the following line:
gcc -E -DVERSION=test -o incl.list incl.c

What I would to have in my code is
  char version = "test";

I can get test into my c code, but cannot figure out how to use as a string.

Following is some test code and output which have used to try to generate what
I want.
int
main()
{
 #define vers VERSION
 #define _string(x) #x
 #define echo(x) x
 #define echo2(x) "##x"
 #define echo3(x) "x"
 #define echo4(x) "##x##"
 _string(vers);
 echo(vers);
 echo(VERSION);
 echo2(vers);
 echo2(VERSION);
 echo3(vers);
 echo3(VERSION);
 echo4(VERSION);
 vers;
 "vers";
}


preprocessor output from above
# 1 "incl.c"
int
main()
{






 "vers" ;
 test   ;
 test  ;
 "##x" ;
 "##x" ;
 "x" ;
 "x" ;
 "##x##" ;
 test  ;
 "vers";
}
Technical Details
Message-ID: <1993Apr2.172512.21462@ods.com>
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!decwrl!uunet!ods!chris

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11318c,6ca91abe63203299,start
X-Google-Attributes: gid11318c,public
X-Google-ArrivalTime: 1993-04-02 09:46:23 PST
Newsgroups: gnu.gcc.help
Path: arc1-ca.pugleaf.net!gmd.de!newsserver.jvnc.net!darwin.sura.net!zaphod.mps.ohio-state.edu!usc!elroy.jpl.nasa.gov!decwrl!uunet!ods!chris
From: chris@ods.com (Chris Atkins)
Subject: Passing string constant with -D
Message-ID: <1993Apr2.172512.21462@ods.com>
Organization: Optical Data Systems, Inc.
X-Newsreader: TIN [version 1.1 PL9]
Date: Fri, 2 Apr 1993 17:25:12 GMT
Lines: 57