By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,652 Members | 1,698 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,652 IT Pros & Developers. It's quick & easy.

UCHAR_MIN & UCHAR_MAX

P: n/a
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

--
______________________________________
I se the lightat the end, but every time I take a step it's get dim.
Nov 14 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
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>

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

"C is a sharp tool"

Nov 14 '05 #2

P: n/a
yes,

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

thanx

On Sun, 30 Jan 2005 16:56:57 +0100, Emmanuel Delahaye
<em***@YOURBRAnoos.fr> wrote:
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>


--
______________________________________
I se the lightat the end, but every time I take a step it's get dim.
Nov 14 '05 #3

P: n/a
Carramba <no****@privet.net> wrote:
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?

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #4

P: n/a
Carramba wrote:

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.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson

Nov 14 '05 #5

P: n/a
Carramba wrote on 30/01/05 :
yes,

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

thanx

On Sun, 30 Jan 2005 16:56:57 +0100, Emmanuel Delahaye <em***@YOURBRAnoos.fr>
wrote:
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.

Nov 14 '05 #6

P: n/a
Emmanuel Delahaye <em***@yourbranoos.fr> wrote:
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?

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #7

P: n/a
S.Tobias <si***@famous.bedbug.pals.invalid> wrote:
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).

--
Stan Tobias
mailx `echo si***@FamOuS.BedBuG.pAlS.INVALID | sed s/[[:upper:]]//g`
Nov 14 '05 #8

P: n/a
S.Tobias wrote on 31/01/05 :
Emmanuel Delahaye <em***@yourbranoos.fr> wrote:
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!

--
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.

Nov 14 '05 #9

P: n/a
Emmanuel Delahaye wrote:
S.Tobias wrote on 31/01/05 :
Emmanuel Delahaye <em***@yourbranoos.fr> wrote:
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);

--
Peter

Nov 14 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.