public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* RE: Please help me passing a path to preprocessor
@ 2003-11-25 16:54 lrtaylor
  0 siblings, 0 replies; 5+ messages in thread
From: lrtaylor @ 2003-11-25 16:54 UTC (permalink / raw)
  To: jp.guillemin; +Cc: gcc-help

That works so long as you don't have any spaces or characters that the
shell will try and interpret in the string.  It's cleaner and safer just
to put the single quotes around the string.  That way you don't have to
worry about what characters are in your string, and you can live a happy
and fulfilling life. :-)

Cheers,
Lyle

-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of jp.guillemin@free.fr

Hi Eljay, Mihnea,

Thank you for the solution,

For information I've found another one :

-DMYPATH=\"/usr/local/thepath\"

then the shell doesn't parse the " anymore

Regards

JP


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Please help me passing a path to preprocessor
  2003-11-25 14:47 ` Eljay Love-Jensen
@ 2003-11-25 16:40   ` jp.guillemin
  0 siblings, 0 replies; 5+ messages in thread
From: jp.guillemin @ 2003-11-25 16:40 UTC (permalink / raw)
  To: Eljay Love-Jensen; +Cc: gcc-help

Hi Eljay, Mihnea,

Thank you for the solution,

For information I've found another one :

-DMYPATH=\"/usr/local/thepath\"

then the shell doesn't parse the " anymore

Regards

JP

Selon Eljay Love-Jensen <eljay@adobe.com>:

> Hi jp,
> 
> If you are using MYPATH as a string in your source code, you may want to put
> double-quotes around it in the define in the makefile.
> 
> -DMYPATH='"/usr/local/thepath"'
> 
> Note that the single-quotes are chomped by the shell that the make spawns to
> launch the compiler.
> 
> Another solution is to string-ize the MYPATH macro variable in your code
> via:
> 
> #define STR_2(x) #x
> #define STR(x) STR_2(x)
> 
> STR(MYPATH)
> 
> The helper macro function STR_2 is necessary so the STR x parm gets expanded.
>  Otherwise you'd end up with "MYPATH" instead of the expansion of MYPATH into
> /usr/local/thepath that you are hoping for, which STR_2 then stringifies.
> 
> You may want to do this instead for STR_2...
> 
> #define STR_2(x) L ## #x
> 
> ...if you need to work with wchar_t strings instead.
> 
> HTH,
> --Eljay
> 
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Please help me passing a path to preprocessor
  2003-11-25 14:10 jp.guillemin
  2003-11-25 14:19 ` Mihnea Balta
@ 2003-11-25 14:47 ` Eljay Love-Jensen
  2003-11-25 16:40   ` jp.guillemin
  1 sibling, 1 reply; 5+ messages in thread
From: Eljay Love-Jensen @ 2003-11-25 14:47 UTC (permalink / raw)
  To: jp.guillemin, gcc-help

Hi jp,

If you are using MYPATH as a string in your source code, you may want to put double-quotes around it in the define in the makefile.

-DMYPATH='"/usr/local/thepath"'

Note that the single-quotes are chomped by the shell that the make spawns to launch the compiler.

Another solution is to string-ize the MYPATH macro variable in your code via:

#define STR_2(x) #x
#define STR(x) STR_2(x)

STR(MYPATH)

The helper macro function STR_2 is necessary so the STR x parm gets expanded.  Otherwise you'd end up with "MYPATH" instead of the expansion of MYPATH into /usr/local/thepath that you are hoping for, which STR_2 then stringifies.

You may want to do this instead for STR_2...

#define STR_2(x) L ## #x

...if you need to work with wchar_t strings instead.

HTH,
--Eljay


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Please help me passing a path to preprocessor
  2003-11-25 14:10 jp.guillemin
@ 2003-11-25 14:19 ` Mihnea Balta
  2003-11-25 14:47 ` Eljay Love-Jensen
  1 sibling, 0 replies; 5+ messages in thread
From: Mihnea Balta @ 2003-11-25 14:19 UTC (permalink / raw)
  To: jp.guillemin, gcc-help

In gcc, you would write:
#define MYPATH "/bla"
Thus, the compile command should be:

	gcc -DMYPATH='"/bla"' a.c

Please note that you can't use
	gcc -DMYPATH="/bla" a.c
since the command interpreter will eat the double quotes. That's why the 
single quotes are there.

On Tuesday 25 November 2003 16:10, jp.guillemin@free.fr wrote:
> Hello,
>
> I think my question is a very simple one...
>
> I'm trying to declare a preprocessor constant with -D
> MYPATH='/usr/local/thepath/' (from a makefile)
>
> - The constant is found declared by preprocessor
> - I get a "Syntax error near `/' token"
>
> Best regards
> jp
>
>
>
>
> ---------------------------------------------------------------
> Acasa.ro vine cu albumele, tu vino doar cu pozele ;)
> http://poze.acasa.ro/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Please help me passing a path to preprocessor
@ 2003-11-25 14:10 jp.guillemin
  2003-11-25 14:19 ` Mihnea Balta
  2003-11-25 14:47 ` Eljay Love-Jensen
  0 siblings, 2 replies; 5+ messages in thread
From: jp.guillemin @ 2003-11-25 14:10 UTC (permalink / raw)
  To: gcc-help

Hello,

I think my question is a very simple one...

I'm trying to declare a preprocessor constant with -D MYPATH='/usr/local/thepath/'
(from a makefile)

- The constant is found declared by preprocessor
- I get a "Syntax error near `/' token"

Best regards
jp


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-11-25 16:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-25 16:54 Please help me passing a path to preprocessor lrtaylor
  -- strict thread matches above, loose matches on Subject: below --
2003-11-25 14:10 jp.guillemin
2003-11-25 14:19 ` Mihnea Balta
2003-11-25 14:47 ` Eljay Love-Jensen
2003-11-25 16:40   ` jp.guillemin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).