Re: [avr-gcc-list] Strings: escape sequence to insert arbitrary hex value ?
On Thursday 05 February 2009 15:02:51 Vincent Trouilliez wrote: Hello, All on-line tutorials on C just do'nt seem to cover all these practical little things I need... these tutorials aren't much help for day to day issues with microcontroller programming I find :-/ Problem: in the strings I define, some of the characters are custom defined (ASCII codes 0 to 7 in a text LCD module). I have some defines like such: #define LCD_CUSTOM_CHAR_FOO any value from 0 to 7 and 0x80 and up char example[] = Example String; Now I need to insert the define LCD_CUSTOM_CHAR_FOO somewhere in the string, and have the compiler replace it with the hex code it stands for... how to instruct the compiler to do so ?! You can define it like so.. #define LCD_CUSTOM_CHAR_FOO \012 then you can do.. char example[] = foo LCD_CUSTOM_CHAR_FOO bar; You might be able to do something more clever but I don't know how :) -- Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au The nice thing about standards is that there are so many of them to choose from. -- Andrew Tanenbaum GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C signature.asc Description: This is a digitally signed message part. ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
Re: [avr-gcc-list] Strings: escape sequence to insert arbitrary hex value ?
On Thursday 05 February 2009 17:22:49 Vincent Trouilliez wrote: On Thu, 5 Feb 2009 16:28:55 +1030 Daniel O'Connor docon...@gsoft.com.au wrote: I had a go at getting that to work with preprocessor magic but I don't think it's possible (I'm no CPP guru though). Actually, how about.. #define FOO \070 #define getOrd(x) (x)[0] Oh, works impeccably, thanks Daniel ! :-) Glad to help. As a newbee, so far I have never ventured into using #defines for anything else than plain constants, but looks like making functions is not that difficult it appears in your example, yet incredibly useful/practical ! :o) Yes.. There are plenty of caveats (check the C FAQ for examples) but they are very useful for collapsing repeated code that won't go well into a function because it needs local context. -- Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au The nice thing about standards is that there are so many of them to choose from. -- Andrew Tanenbaum GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C signature.asc Description: This is a digitally signed message part. ___ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list