473,804 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C-Preprocessor Experts wanted...

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"##'\'##ar g
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 kl***@klausix.n et



Mar 8 '07 #1
1 2068
On Mar 8, 4:42 pm, "Klaus Siegesleitner" <k...@klausix.n etwrote:
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 k...@klausix.ne t
As you can see, Google makes this... difficult. Hope it's helpful
anyway.

-=Dave

Mar 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
3266
by: Tim Tyler | last post by:
Are there many PHP public domain projects out there? I'm particularly interested in CMS project materials. So far - outside of my own projects - I've found /very/ little PD PHP material out there. A large proportion of the PHP community seems to have embraced the Gnu licenses - complete with all their restrictions on the users of the software.
8
2813
by: Dorthe Luebbert | last post by:
Hi, we have to convert a quite large ISO-application (Mysql4, PHP5) to UTF8. We found out so far that there is no collation for MySQL which is able to sort all character sets correctly. So this has to be done. And there might be some problems with string functions as not all string functions have multibyte aquivalents. What are your experiences with this topic? Any hints?
53
4017
by: ROSY | last post by:
hello, response if u ,on all level of questions::: 1.how a self deletable .exe file deleted on some future date & time without invoking the .exe itself? 2.if we want that any wildcard characters in command line arguments should be appropriately expanded,are we reqd. 2 make any special provision?if yes,which? 3.why :: printf("%%%%%") ; output %%%. 4.how 2 run a .obj file without previously creating any .exe?
0
9595
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6867
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3835
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3002
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.