UCHAR_MIN & UCHAR_MAX

C

Carramba

hi!

how do I call UCHAR_MIN & UCHAR_MAX ?
printf("unsigned-char: [%c, %c]\n", UCHAR_MIN, UCHAR_MAX);
Iam getting error with %c? with one I should use? and why?

thax in advance
 
C

Carramba

yes,

the problem was there isn't UCHAR_MIN .... only MAX ...

thanx

Carramba wrote on 30/01/05 :
how do I call UCHAR_MIN & UCHAR_MAX ?
printf("unsigned-char: [%c, %c]\n", UCHAR_MIN, UCHAR_MAX);
Iam getting error with %c? with one I should use? and why?

What error ?

First of all, try with "%d" to see the values (in decimal).

BTW, I guess you included <limits.h>
 
S

S.Tobias

Carramba said:
how do I call UCHAR_MIN & UCHAR_MAX ?
^^^^^^^^^
What this? -------^
printf("unsigned-char: [%c, %c]\n", UCHAR_MIN, UCHAR_MAX);
Iam getting error with %c? with one I should use? and why?

What's the error message?
 
C

CBFalconer

Carramba said:
how do I call UCHAR_MIN & UCHAR_MAX ?
printf("unsigned-char: [%c, %c]\n", UCHAR_MIN, UCHAR_MAX);
Iam getting error with %c? with one I should use? and why?

First you need to #include <limits.h>. Then you need to use %d,
since those macros describe the limits of the type, and those
limits are not necessarily printable. Third, there is no
UCHAR_MIN, it is zero, as for all unsigned types.
 
E

Emmanuel Delahaye

Carramba wrote on 30/01/05 :
yes,

the problem was there isn't UCHAR_MIN .... only MAX ...

thanx

Carramba wrote on 30/01/05 :
how do I call UCHAR_MIN & UCHAR_MAX ?
printf("unsigned-char: [%c, %c]\n", UCHAR_MIN, UCHAR_MAX);
Iam getting error with %c? with one I should use? and why?

What error ?

First of all, try with "%d" to see the values (in decimal).

BTW, I guess you included <limits.h>

After brain shaking...

UCHAR_MIN doesn't exist. It's 0 by definition.

BTW, the correct formatter is "%u".

printf("unsigned-char: [%c, %c]\n", 0, UCHAR_MAX);

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Mal nommer les choses c'est ajouter du malheur au
monde." -- Albert Camus.
 
S

S.Tobias

Emmanuel Delahaye said:
BTW, the correct formatter is "%u".
printf("unsigned-char: [%c, %c]\n", 0, UCHAR_MAX);

Didn't you mean to write:
printf("unsigned-char: [%u, %u]\n", 0, UCHAR_MAX);
?

UCHAR_MAX constant is promoted to either singed or unsigned int.
Since the value is positive, either result must have the same
representation. The difference is only in the type. Is a cast
before the constants recommended or not in this case?
 
S

S.Tobias

S.Tobias said:
UCHAR_MAX constant is promoted to either singed or unsigned int.
XXXXXXXXXXXXXX
UCHAR_MAX _is_ either singed or unsigned int (depending on the result
of the promotion of unsigned char - cf. 5.2.4.2.1).
 
E

Emmanuel Delahaye

P

Peter Nilsson

Emmanuel said:
S.Tobias wrote on 31/01/05 :
Emmanuel Delahaye said:
BTW, the correct formatter is "%u".

printf("unsigned-char: [%c, %c]\n", 0, UCHAR_MAX);

Didn't you mean to write:
printf("unsigned-char: [%u, %u]\n", 0, UCHAR_MAX);
?

Sure!

%u expects an unsigned int, not an int. The wording of the
standard doesn't guarantee that %u will work in this case
(although that _was_ the intent of the committee.)

That said, it is arguable whether a hosted implementation
can be considered conforming if UCHAR_MAX promotes to
unsigned int, so I think that...

printf("unsigned-char: [%d..%d]\n", 0, UCHAR_MAX);

....is safer. If you're truly paranoid, then use...
printf("unsigned-char: [%u..%u]\n", 0u, 0u + UCHAR_MAX);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,351
Latest member
RoxiePulli

Latest Threads

Top