Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > C-Preprocessor Experts wanted...

Reply
Thread Tools

C-Preprocessor Experts wanted...

 
 
Klaus Siegesleitner
Guest
Posts: n/a
 
      03-08-2007
Hi all!
sorry, my first posting to this newsgroup - hope everything works fine...

I'm looking for a macro that converts an octal number assigned to a
preprocessor symbol (via a simple #define) into a string-fragment that can
be added/embedded to an new string literal.
This string-fragment shall consist of two characters, both defined as octal
numbers:
the first octal number \001 (acting as an escape symbol) and
the second octal number that has been passed to the macro via its defined
preprocessor symbol.

example:
#define SYMBOL_ID_SUN 010
#define SYMBOL_ID_RAIN 011
#define SYMBOL_ID_FOG 012

#define CONVERT(arg) <whatever does the conversion>

char string[] = "the wether is " CONVERT(SYMBOL_ID_FOG) " today.";

should result in:

"the wether is \001\012 today"


I tried something like
#define CONVERT(arg) "\001"##str
or
#define CONVERT(arg) "\001"##'\'##arg
or
....
but most of the time got troubles because of the interpretation of the \ as
a linebreak.

any c-preprocessor expert here that can help??

thanks a lot,
klaus!


p.s.: if possible also reply to http://www.velocityreviews.com/forums/(E-Mail Removed)







 
Reply With Quote
 
 
 
 
Dave Hansen
Guest
Posts: n/a
 
      03-09-2007
On Mar 8, 4:42 pm, "Klaus Siegesleitner" <(E-Mail Removed)> wrote:
> Hi all!
> sorry, my first posting to this newsgroup - hope everything works fine...
>
> I'm looking for a macro that converts an octal number assigned to a

[...]
>
> example:
> #define SYMBOL_ID_SUN 010
> #define SYMBOL_ID_RAIN 011
> #define SYMBOL_ID_FOG 012
>
> #define CONVERT(arg) <whatever does the conversion>
>
> char string[] = "the wether is " CONVERT(SYMBOL_ID_FOG) " today.";
>
> should result in:
>
> "the wether is \001\012 today"
>


How about something like this:

---begin included file---

C:\Dave>type pp.c

#define Stringize(x) #x
#define SlashString(x) Stringize(\001\x)

#define Convert(x) SlashString(x)

#define SYMBOL_ID_FOG 012

char * s = "The weather is " Convert(SYMBOL_ID_FOG) " today";

C:\Dave>gcc -E pp.c
# 1 "pp.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "pp.c"
# 9 "pp.c"
char * s = "The weather is " "\001\012" " today";

C:\Dave>

--- End included file ---

Note that string literals separated only by whitespace get
concatenated.

> p.s.: if possible also reply to (E-Mail Removed)


As you can see, Google makes this... difficult. Hope it's helpful
anyway.

-=Dave

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any EE experts out there? hermes Wireless Networking 20 12-01-2005 06:15 AM
HTTPS SSLeay problems - any experts out there? Ira Lee Perl 0 06-29-2004 10:16 PM
Experts: Is it possible to combine policy-based MPLS-TE + MPLS-VPN ? Herbert Haas Cisco 0 01-09-2004 09:20 AM
OT: IT Experts Required Internetworkresource.com Cisco 0 11-28-2003 05:25 PM
Experts on embedding Perl in C wanted: Weird problem on RH7.3/Perl 5.6.1 David F. Skoll Perl 2 11-14-2003 05:37 PM



Advertisments