Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Can preprocessing do it?

1 view
Skip to first unread message

Alex Vinokur

unread,
Jan 11, 1999, 3:00:00 AM1/11/99
to
Hi,

I am using the following macros:
static char __FILE__.KKK[] = "@(#)Header :: "__FILE__;

After preprocessing I have (for example, in Foo.H):
static char "Foo.H".KKK[] = "@(#)Header :: ""Foo.H";

But I need :
static char Foo.H.KKK[] = "@(#)Header :: ""Foo.H";
(instead "Foo.H" I need Foo.H)

Is it possible?

Thanks in advance,
Alex


--
comp.lang.c.moderated - cl...@plethora.net

Christopher R. Volpe

unread,
Jan 12, 1999, 3:00:00 AM1/12/99
to

Alex Vinokur wrote:
>
> Hi,
>
> I am using the following macros:
> static char __FILE__.KKK[] = "@(#)Header :: "__FILE__;
>
> After preprocessing I have (for example, in Foo.H):
> static char "Foo.H".KKK[] = "@(#)Header :: ""Foo.H";
>
> But I need :
> static char Foo.H.KKK[] = "@(#)Header :: ""Foo.H";
> (instead "Foo.H" I need Foo.H)

You can't do what you think you want to do, and you don't really want to
do what you think you want to do. The post-preprocesseded code you are
trying to achieve is a syntax error. The periods form a struct field
reference that constitutes gibberish in this context.

Why do you think you need to do this? Since the array is being declared
static, there is no reason for a unique identifier, is there?

--
Christopher R. Volpe fax: 518-387-6981
Computer Scientist email: vol...@crd.ge.com
GE Corporate R&D (Unsolicited email is not welcome)
P.O. Box 8, Schenectady, NY 12309 www: http://www.crd.ge.com/~volpecr
*** News postings do not constitute a GE corporate communication ***
--
comp.lang.c.moderated - cl...@plethora.net

Andy Bachorski

unread,
Jan 18, 1999, 3:00:00 AM1/18/99
to
In article <clcm-1999...@plethora.net>, Alex Vinokur
<alexande...@telrad.co.il> wrote:

>Hi,
>
>I am using the following macros:
> static char __FILE__.KKK[] = "@(#)Header :: "__FILE__;
>
>After preprocessing I have (for example, in Foo.H):
> static char "Foo.H".KKK[] = "@(#)Header :: ""Foo.H";
>
>But I need :
> static char Foo.H.KKK[] = "@(#)Header :: ""Foo.H";
> (instead "Foo.H" I need Foo.H)
>

>Is it possible?


I wondered about this same thing for some time, and a while back figured
out how to do it. The trick to doing what you are after is that you need
to use an intermediate macro to cause the quoting to happen the way you
want it to.

Here is some code taken from a debugging header I include in my Mac
projects. I should do what you are after.

Andy B


#if DEBUGGING

#define FileAndLine File: __FILE__ Line: __LINE__
/*
* The FileAndLine macro provides a formatted string conaining the
* name of the current file, and the line in the file where it is
* used.
*
* output: File: "DebugMacroTester.c" Line: 12
*/

#define QuoteString( str ) #str
/*
* The QuoteString macro puts quotes ("") around a given string.
*
* Useful when you want to included a quoted string in another string
* generated with another macro. For example:
*
* QuoteString( A string to quote. )
* output: "A string to quote."
*
* One limitation to this macro is that it will not quote the result
* of another macro unless it us used inside yet another macro.
*
* For example:
*
* QuoteString( FileAndLine )
* output: "FileAndLine"
*
* However, when used inside another macro, such as:
*
* #define MakePString(str) QuoteString( \p str )
*
* When used like this:
*
* MakePString( FileAndLine )
* output: "\p File: \"DebuggingTools.h\" Line: 44"
*
* NOTE: The QuoteString macro doesn't work with strings that
* contain embedded single or double quote characters ( ' or " ).
* Other types of quotes, such as smart quotes (Œ ¹ or ³ ²) will work.
*/

#endif
--
comp.lang.c.moderated - cl...@plethora.net

James Hu

unread,
Jan 19, 1999, 3:00:00 AM1/19/99
to
On Mon, 18 Jan 1999 22:39:44 GMT, Andy Bachorski <cav...@ricochet.nospam.net> wrote:
>In article <clcm-1999...@plethora.net>, Alex Vinokur
><alexande...@telrad.co.il> wrote:

>>I am using the following macros:
>> static char __FILE__.KKK[] = "@(#)Header :: "__FILE__;
>>
>>After preprocessing I have (for example, in Foo.H):
>> static char "Foo.H".KKK[] = "@(#)Header :: ""Foo.H";
>>
>>But I need :
>> static char Foo.H.KKK[] = "@(#)Header :: ""Foo.H";
>> (instead "Foo.H" I need Foo.H)
>>
>>Is it possible?

>I wondered about this same thing for some time, and a while back figured
>out how to do it. The trick to doing what you are after is that you need
>to use an intermediate macro to cause the quoting to happen the way you
>want it to.
>
>Here is some code taken from a debugging header I include in my Mac
>projects. I should do what you are after.

[snip]

I don't think your solution addresses Alex's problem. He wants to
create an identifier name based on the name of the file, not a string
with quotations around the file name.

I can't think of any way to accomplishing what Alex wants.

--
James C. Hu <j...@cs.wustl.edu> Computer Science Doctoral Candidate
http://www.cs.wustl.edu/~jxh/ Washington University in Saint Louis
>>>>>>>>>>>>> I use *SpamBeGone* <URL:http://www.internz.com/SpamBeGone/>
--
comp.lang.c.moderated - cl...@plethora.net

0 new messages