Unsigned Chars doesn't work

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello fellow freaks!

In AVR studio 4.13 the option "Unsigned Chars (-funsigned-char)" doesn't work. There is no difference with or without it.

What could be the problem, and can it be fixed some how?

Using WinAVR-20070122 and AvrStudio 4.13 build 528.

Any ideas as welcome.

Best regards
Bjorn

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Show us an example that demonstrates it "not working".

All that tick box in Studio does is decide whether the compiler invocation is passed -funsigned-char or not. There's no doubt that avr-gcc (4.1.1) implements this behaviour correctly.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello again!

The problem is basically when I do this:

...
lcd_print("HELLOWORLD!");
...
...
void lcd_print(unsigned char* s) {
    ...
}

I get no errors when I use cast.

lcd_print((unsigned char*)"HELLOWORLD!")

It's strange, since I never had that problem before.

Best regards
Bjorn

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try:

void lcd_print(char* s) {

The C standard:

http://www.open-std.org/JTC1/SC2...

in section 6.4.5 says that string literals are of type char not signed char or unsigned char

The use of -funsigned-char or -fsigned-char will affect the signedness of:

{
  char c;

but I don't think you can control string literals like this.

Cliff

Last Edited: Fri. Apr 20, 2007 - 02:11 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, that would work.

But this is only one example. How come I get tons of warnings when I updated AVRstudio and WinAVR?

Seems to me that the -unsigned flag doesn't work ok. Even If I see that AVRstudio uses in when sending the compile command.

/Bjorn

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

It's certainly true that GCC 4.1.1 seems to be MUCH stricter about issuing warnings over signedness than 3.4.6 was.

By the way I think I edited my post above after you posted your last message - does that explanation of what -funsigned-char controls help your understanding?

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
Show us an example that demonstrates it "not working".
hmmm I tried the switch when I was messing around with Microcarl's lcd back pack a few days ago. Some of the variable had to be declared unsigned so I checked the -funsigned-char and the errors were still there untill I changed the code and put the unsigned in front of the variables. Cliff you may remember me mentioning it on that thread.

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

According to the C standard,
char, signed char and unsigned char are distinct types.
Pointers to them are therefore also distinct types.
char is required to behave exactly like signed char
or exactly like unsigned char,
except that they are not interchangeable.
Since integral variables may be
assigned to each other promiscuously,
that mostly means that their pointers
ought not be assigned to each other.
I don't remember if a diagnostic is required.
Diagnostics are allowed to change
with the phase of the moon.

"Demons after money.
Whatever happened to the still beating heart of a virgin?
No one has any standards anymore." -- Giles