char is unsigned

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

Hi.

I just found out that char is unsigned. Tricky that. I had to write signed char to get what I wanted. (Imagecraft but it should be ANSII C). Somethere deep in the back of my brain I think I had this information stored but it had to be refreshed.

I also found that running a for loop from n to 0 saves 1 word. That was how I found it, the test for i>=0 never ended.

/Bengt

My favorites:
1. My oscilloscope, Yokogawa DLM2024.
2. My soldering iron, Weller WD2M, WMRP+WMRT.
3. JTAGICE3 debugger.

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

Quote:
I just found out that char is unsigned.

In the C standard, char is neither signed nor unsigned. Compilers may have options to standardize it to one or another, however. If you want one or the other specifically then you should declare it explicitly.

Regards,
Steve A.

The Board helps those that help themselves.

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

My experience is that char is usually signed, which always struck me as a bit odd (excuse pun).

C: i = "told you so";

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

Just to note that most GCC Makefiles will tend to include:

CFLAGS += -funsigned-char

to remove any doubt about this. Maybe Imagecraft has an option for force how it should be interpreted.

Note however that even with -funsigned-char (which forces "char c" to be interpreted as "unsigned char c") that if you use a character or string literal it remains as implied type "char" and is neither signed nor unsigned.

Cliff

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

The ImageCraft documentation is quite explicit about char being unsigned: page 20, "Converting from other ANSI C Compilers" bullet point 1 - "Our char data type is unsigned"

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Just out of interest does Imagecraft have stdint.h? If it did then using uint8_t or int8_t makes it completely unequivocal as to the exact type (and width) of a variable (which is, of course, their raison d'etre)

Of course library functions like strcpy() will still moan as they are looking for "char *" etc.