This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Macro question again


I have the same trouble with string concatenation ...

	Yves
----- cut here -----
I'm using __CONCAT() defined in /usr/include/sys/cdefs.h

#define __CONCAT(x,y) x ## y

With previous gcc version or other compiler I newer have a warning.
The preprocessor translate the following line
	static char default_path[] = BLOG_TMP_DIR;
to
	static char default_path[] = "/""tmp";

Do somebody know the correct compiler option to remove this warning?

	Thanks,

Yves
============= Cut Here =============
#include <stdio.h>

#define BLOG_SEP_DIR "/"
#define BLOG_TMP_DIR __CONCAT(BLOG_SEP_DIR,"tmp")

int main(int argc,char *argv[])
{
	static char default_path[] = BLOG_TMP_DIR;
	static char a[] = __CONCAT("/","tmp");

	printf("[%s]\n",default_path);
	printf("[%s]\n",a);
	return 0;
}
============= Cut Here =============
cc tcpp.c -o tcpp
tcpp.c:7:42: warning: pasting "BLOG_SEP_DIR" and ""tmp"" does not give a
valid preprocessing token
tcpp.c:8:31: warning: pasting ""/"" and ""tmp"" does not give a valid
preprocessing token

----- curt here -----

> -----Message d'origine-----
> De : gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org]De la
> part de Joe MacDonald
> Envoyé : vendredi 10 mai 2002 21:29
> À : gcc-help@gcc.gnu.org
> Objet : Macro question again
>
>
> Hey everyone,
>
> About six months ago I asked almost exactly the same question and got an
> answer from John Love-Jensen, (if you're still out there John, thanks!)
> but now I'm in a slightly different situation and, while not pressing,
> I'd really like to know if anyone has come up with an alternative way to
> do this.
>
> I have the following macro:
>
> #define trace(level, format, ...)                                    \
> do {                                                                 \
>    if (level < debugLevel)                                           \
>    {                                                                 \
>        fprintf(stderr, "%s:%s:%d> ", __func__, __FILE__, __LINE__);  \
>        fprintf(stderr, format, ##__VA_ARGS__);                       \
>    }                                                                 \
> } while(0)
>
> So that I can make calls like:
>
>    trace(5, "some trace information = %d\n", anInteger);
>
> Throughout my code.  It works fine, but I get a pile of "pasting would
> not give a valid preprocessing token" warnings from gcc 2.96 (ugh) and
> 3.0.1 on my RH 7.0 linux box.  John had suggested a bit of a macro-dance
> using vfprintf(...) but I'm afraid I haven't been able to arrange the
> same functionality without the warnings.  Is this approach fundamentally
> flawed?  Can someone suggest a better (but still C) way to do the same
> thing with a macro?
>
> Thanks,
> -Joe.
>
> --
> Joe MacDonald
> :wq
> ---
>
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.330 / Virus Database: 184 - Release Date: 28/02/2002
>
---

Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.330 / Virus Database: 184 - Release Date: 28/02/2002


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]