#line directive and -D option

Jan Engelhardt jengelh@medozas.de
Wed Dec 17 02:40:00 GMT 2008


On Wednesday 2008-12-17 02:56, Hiroki Kaminaga wrote:
>Hi,
>
>From: "John (Eljay) Love-Jensen" <eljay@adobe.com>
>> Hi Hiroki,
>> 
>> Worked on my machine.
>...
>> Depending on your shell, you may need to escape the quotes, such as one of these two ways:
>> -D MYNAME=\"macrotest\"
>> -D MYNAME='"macrotest"'
>
>Ah, above worked, thank you!
>
>By the way, is there any method to strip strings prefix passed to
>__FILE__ macro?  If .c file is specified by abosolute path, __FILE__
>also prints absolute path:

Well use a function that returns the basename. Something like

	/* from libHX-1.28/src/string.c */
	EXPORT_SYMBOL char *HX_basename(const char *s)
	{
		const char *p;
		if ((p = strrchr(s, '/')) != NULL)
			return const_cast1(char *, p + 1);
		return const_cast1(char *, s);
	}

and

>$ cat macro-test.c 
>#include <stdio.h>
>int main(void)
>{
>  printf ("%s: .... \n", __FILE__);
   printf("%s: ...\n", HX_basename(__FILE__));
>  return 0;
>}



More information about the Gcc-help mailing list