Path: utzoo!utgpu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!sdd.hp.com!zaphod.mps.ohio-state.edu!julius.cs.uiuc.edu!news.cs.indiana.edu!noose.ecn.purdue.edu!mentor.cc.purdue.edu!ksb From: ksb@mentor.cc.purdue.edu (Kevin Braunsdorf) Newsgroups: alt.hackers Subject: cc hack to check if we get a string on an int in a -Ddefine Keywords: cc, hack, -D, run-time Message-ID: <4537@mentor.cc.purdue.edu> Date: 25 Jan 91 21:59:02 GMT Reply-To: ksb@mentor.cc.purdue.edu (Kevin Braunsdorf) Organization: Lines: 31 Approved: news@cc.purdue.edu I wanted to let a configure script give me a service name or a port number, like: cc -DPORT=\"junk\" server.c or cc -DPORT=2189 server.c But I needed to be able to check in the C code to see which one I got: /* $Compile(1): cc -DPORT=\"123\" %f * $Compile(1): cc -DPORT=123 %f */ main() { static char a[] = { PORT }; if (1 != sizeof(a) || sizeof(PORT) != sizeof(PORT+1)) { printf("string %s\n", a); } else { printf("int %d\n", PORT); } exit(0); } -- If you're not part of the solution, you're part of the problem. kayessbee, Kevin Braunsdorf, ksb@cc.purdue.edu, pur-ee!ksb, purdue!ksb