Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-08 Thread Joerg Wunsch
David Kelly  wrote:

> Odds are that is an avr-gcc patch and not standard gcc. Am more certain
> the support of entering binary values is an avr-gcc enhancement because
> I see the patch file in the FreeBSD port.

You're confusing that with binary constants, that are introduced by
the string "0b".  I've eventually been able to convince the GCC folks
to accept that as a general extension, so it's now no longer an
AVR-GCC specific hack but a generic GCC thing.  If they ever come
round to decide about a new C standard, so they can at least no longer
claim "lack of precedent" next time (which they did when someone
requested that feature for the ISO C99 standard).

-- 
cheers, J"org   .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-05 Thread Dave Hansen

 From: vincent.trouill...@modulonet.fr
[...]
>
>> ISO C99, section 6.4.4.4, p3:
>> the question-mark ?, [..] is representable according to the following table 
>> of escape
>> sequences: question mark? \?
>
> Interesting. I wonder why the standard deeemd it necessary to provide
> an escape sequence for the question mark ?
 
As other have mentioned, it's to prevent the substitution of trigraphs.  
Trigraphs are a way to express characters that either do not appear is the 
source character set, or are handled poorly by the development environment.  If 
trigraphs are enabled, then
 
   puts("Trigraphs??!");
 
will output "Trigraphs|" (IIRC).  To prevent this, you can use
 
   puts("Trigraphs?\?!");
 
Regards,
 
   -=Dave
 
 

 
_
Windows Live™: E-mail. Chat. Share. Get more ways to connect. 
http://windowslive.com/howitworks?ocid=TXT_TAGLM_WL_t2_allup_howitworks_022009

___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-05 Thread David Kelly
On Thu, Feb 05, 2009 at 07:13:18PM +0100, Vincent Trouilliez wrote:
> > ISO C99, section 6.4.4.4, p3:
> > the question-mark ?, [..] is representable according to the
> > following table of escape sequences: question mark? \?
> 
> Interesting. I wonder why the standard deeemd it necessary to provide
> an escape sequence for the question mark ?
> I do happen to have question marks in my strings, but didn't know
> about the escape sequence so didn't use it, yet the compiler didn't
> complain, and simply put the question mark ASCII code in the string,
> as I expected.
> 
> I understand they phrased it to mean a "possibility", not an
> obligation, but why provide it if they didn't think there were at
> least one use case where it would be mandatory ?

Haven't gone back to the referenced text but perhaps the ? was intended
as wildcard character indicating that any character can be escaped as
itself when in doubt?

-- 
David Kelly N4HHE, dke...@hiwaay.net

Whom computers would destroy, they must first drive mad.


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-05 Thread Vincent Trouilliez
> ISO C99, section 6.4.4.4, p3:
> the question-mark ?, [..] is representable according to the following table 
> of escape
> sequences: question mark? \?

Interesting. I wonder why the standard deeemd it necessary to provide
an escape sequence for the question mark ?
I do happen to have question marks in my strings, but didn't know about
the escape sequence so didn't use it, yet the compiler didn't complain,
and simply put the question mark ASCII code in the string, as I
expected.

I understand they phrased it to mean a "possibility", not an
obligation, but why provide it if they didn't think there were at least
one use case where it would be mandatory ?

Ideas ?

--
Vince


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-05 Thread Dave Hansen



 From: dke...@hiwaay.net
> On Thu, Feb 05, 2009 at 12:13:37AM -0700, Chris Kuethe wrote:
>> On Thu, Feb 5, 2009 at 12:10 AM, Schwichtenberg, Knut
>>  wrote:
>>> As far as I know hex values won't work as expected but octal does!
>>>
>>> I used:
>>>
>>> static char s46[] __attribute__ ((progmem)) = "Hei\342gas"; /* 46 */
>>>
>>> which is written as "Hei?gas" on an LCD.
>> 
>> As far as I know, hex values do work... because I tried that program
>> before pasting it. But some people prefer octal escapes...
> 
> Odds are that is an avr-gcc patch and not standard gcc. Am more certain
> the support of entering binary values is an avr-gcc enhancement because
> I see the patch file in the FreeBSD port.

ISO C99, section 6.4.4.4, p3:
The single-quote ', the double-quote ", the question-mark ?, the backslash \, 
and
arbitrary integer values are representable according to the following table of 
escape
sequences:
single quote' \'
double quote" \"
question mark? \?
backslash\ \\
octal character \octal digits
hexadecimal character \x hexadecimal digits
 
Same section, p6:
The hexadecimal digits that follow the backslash and the letter x in a 
hexadecimal escape
sequence are taken to be part of the construction of a single character for an 
integer
character constant or of a single wide character for a wide character constant. 
The
numerical value of the hexadecimal integer so formed specifies the value of the 
desired
character or wide character.
 
Regards,
 
   -=Dave
 
_
Windows Live™: E-mail. Chat. Share. Get more ways to connect. 
http://windowslive.com/explore?ocid=TXT_TAGLM_WL_t2_allup_explore_022009

___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-05 Thread Vincent Trouilliez
On Thu, 05 Feb 2009 07:58:26 +0100
David Brown  wrote:


Thanks to all the people who replied while I was away !

> An alternative idea is to find an ASCII character that you don't need 
> otherwise (say, "~"), and use it in your strings.  Then do on-the-fly 
> conversion when outputing the strings:
> 
> char example[] = "foo~bar";
> 
> void lcdWriteString(const char* p) {
>   while (char c = *p++) {
>   if (c == '~') {
>   lcdWriteChar(LCD_CUSTOM_CHAR_FOO);
>   } else {
>   lcdWriteChar(c);

Ah yes, as it happens I already do exactly just that, for two caracters:
the lower case 'g' and 'y' letters. The default ones defined in the LCD
module don't look good, so I redefined them (same bitmap but lowered
down one line/pixel, so it lines up better with the surrounding text).


--
Vince


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-05 Thread David Kelly
On Thu, Feb 05, 2009 at 12:13:37AM -0700, Chris Kuethe wrote:
> On Thu, Feb 5, 2009 at 12:10 AM, Schwichtenberg, Knut
>  wrote:
> > As far as I know hex values won't work as expected but octal does!
> >
> > I used:
> >
> > static char s46[] __attribute__ ((progmem)) =  "Hei\342gas";/* 
> > 46 */
> >
> > which is written as "Hei?gas" on an LCD.
> 
> As far as I know, hex values do work... because I tried that program
> before pasting it. But some people prefer octal escapes...

Odds are that is an avr-gcc patch and not standard gcc. Am more certain
the support of entering binary values is an avr-gcc enhancement because
I see the patch file in the FreeBSD port.

-- 
David Kelly N4HHE, dke...@hiwaay.net

Whom computers would destroy, they must first drive mad.


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-05 Thread Juergen Harms
I have made good experience using the fact that the compiler 
concatenates sub-strings. Just dumping examples from existing code:


static char e_origin[] PROGMEM =
"\x1b""AT\x00\x00\x14\x12\x01\x00""C\x7F\x00" ;

This example also illustrates one problem and its solution: the compiler 
has difficulties to distinguish between letters (at least a..f) that are 
part of a constant and letters that are part of a character string. In 
case of such an ambiguity, I simply start a new substring.


Here is a more complicated example that illustrates the transparency of 
comments with respect to concatenation, and that you need not resort to 
substrings as in the case of D\x82marrer (dont ask me why I used 
sub-strings for "CArr\x88""ter - I presently have a small problem and 
cannot try things out).


static char e_idle1[] PROGMEM =
"\x1b""AE\x0B"  // button borders #9
"\x1b""AT\x28\x20\xCC\x32\x11\x00"  // KEY_SHARE + 1
"CArr\x88""ter / D\x82marrer\x00" ;

Good luck!



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-04 Thread Chris Kuethe
On Thu, Feb 5, 2009 at 12:10 AM, Schwichtenberg, Knut
 wrote:
> As far as I know hex values won't work as expected but octal does!
>
> I used:
>
> static char s46[] __attribute__ ((progmem)) =  "Hei\342gas";/* 46 
> */
>
> which is written as "Heißgas" on an LCD.

As far as I know, hex values do work... because I tried that program
before pasting it. But some people prefer octal escapes...

-- 
GDB has a 'break' feature; why doesn't it have 'fix' too?


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


RE: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-04 Thread Schwichtenberg, Knut
As far as I know hex values won't work as expected but octal does!

I used:

static char s46[] __attribute__ ((progmem)) =  "Hei\342gas";/* 46 */

which is written as "Heißgas" on an LCD.

Knut

> -Original Message-
> From: 
> avr-gcc-list-bounces+knut.schwichtenberg=siemens@nongnu.or
> g 
> [mailto:avr-gcc-list-bounces+knut.schwichtenberg=siemens@n
ongnu.org] On Behalf Of Chris Kuethe
> Sent: Thursday, February 05, 2009 8:07 AM
> To: David Brown
> Cc: avr-gcc-list@nongnu.org
> Subject: Re: [avr-gcc-list] Re: Strings: escape sequence to 
> insert arbitrary hex value ?
> 
> #include 
> 
> int main(){
>   char *m = "try use 
> \x68\x65\x78\x20\x65\x73\x63\x61\x70\x65\x73\x3f";
> 
>   printf("%s\n", m);
>   return 0;
> }
> 
> On Wed, Feb 4, 2009 at 11:58 PM, David Brown 
>  wrote:
> > Vincent Trouilliez wrote:
> >>
> >> On Thu, 5 Feb 2009 15:18:44 +1030
> >> "Daniel O'Connor"  wrote:
> >>
> >>> 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 :)
> >>
> >>
> >> Thanks Daniel (and Ivan as well, off-list), that worked a 
> treat ! :-)
> >>
> >> Only drawback I found, is that I must now have TWO 
> #defines for each and
> >> every custom character: one #define to represent the character as a
> >> string, so I can embed it into a string, and also all the 
> #defines I
> >> already had, which represent the actual numerical value, for when I
> >> need to print an individual/discrete character rather than print a
> >> string. It's not the end of the world, but not very 
> elegant either, so
> >> if anybody has a solution to make do with only one define 
> per character,
> >> I am all ears ;-)
> >>
> >
> > An alternative idea is to find an ASCII character that you 
> don't need
> > otherwise (say, "~"), and use it in your strings.  Then do 
> on-the-fly
> > conversion when outputing the strings:
> >
> > char example[] = "foo~bar";
> >
> > void lcdWriteString(const char* p) {
> >while (char c = *p++) {
> >if (c == '~') {
> >lcdWriteChar(LCD_CUSTOM_CHAR_FOO);
> >} else {
> >lcdWriteChar(c);
> >}
> >}
> > }
> >
> > As long as you don't have too many, the overhead won't be 
> bad (and the
> > substitute characters won't be too confusing).  It should 
> also work with
> > characters >= 128 as the substitutes, I believe.
> >
> >
> >
> >
> >
> > ___
> > AVR-GCC-list mailing list
> > AVR-GCC-list@nongnu.org
> > http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> >
> 
> 
> 
> -- 
> GDB has a 'break' feature; why doesn't it have 'fix' too?
> 
> 
> ___
> AVR-GCC-list mailing list
> AVR-GCC-list@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> 


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Re: Strings: escape sequence to insert arbitrary hex value ?

2009-02-04 Thread Chris Kuethe
#include 

int main(){
char *m = "try use \x68\x65\x78\x20\x65\x73\x63\x61\x70\x65\x73\x3f";

printf("%s\n", m);
return 0;
}

On Wed, Feb 4, 2009 at 11:58 PM, David Brown  wrote:
> Vincent Trouilliez wrote:
>>
>> On Thu, 5 Feb 2009 15:18:44 +1030
>> "Daniel O'Connor"  wrote:
>>
>>> 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 :)
>>
>>
>> Thanks Daniel (and Ivan as well, off-list), that worked a treat ! :-)
>>
>> Only drawback I found, is that I must now have TWO #defines for each and
>> every custom character: one #define to represent the character as a
>> string, so I can embed it into a string, and also all the #defines I
>> already had, which represent the actual numerical value, for when I
>> need to print an individual/discrete character rather than print a
>> string. It's not the end of the world, but not very elegant either, so
>> if anybody has a solution to make do with only one define per character,
>> I am all ears ;-)
>>
>
> An alternative idea is to find an ASCII character that you don't need
> otherwise (say, "~"), and use it in your strings.  Then do on-the-fly
> conversion when outputing the strings:
>
> char example[] = "foo~bar";
>
> void lcdWriteString(const char* p) {
>while (char c = *p++) {
>if (c == '~') {
>lcdWriteChar(LCD_CUSTOM_CHAR_FOO);
>} else {
>lcdWriteChar(c);
>}
>}
> }
>
> As long as you don't have too many, the overhead won't be bad (and the
> substitute characters won't be too confusing).  It should also work with
> characters >= 128 as the substitutes, I believe.
>
>
>
>
>
> ___
> AVR-GCC-list mailing list
> AVR-GCC-list@nongnu.org
> http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
>



-- 
GDB has a 'break' feature; why doesn't it have 'fix' too?


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list