basic c i/o and EOF

T

The Real OS/2 Guy

ITYM "not lucky".

No, 'abc' or 'EOF' or 'BAD' is NOT a character. A character is a
single char, not a sequence of chars. A sequence of chars is known a
string, but a string must be in double quotes. So the compiler will
throw a diagnistic.

Quoth n869 (6.4.4.4):
--------
Description

[#2] An integer character constant is a sequence of one or
^^^^^^
more multibyte characters enclosed in single-quotes, as in
^^^^
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.
--------

So 'abc' is no less a character constant than 'a'. It may or may not
correspond to an acceptable char value, but it's perfectly acceptable as a
source code construct. (And, just for if you're going to try to nitpick
on the 'may not correspond to an acceptable value', I'll point out that
'a' isn't a "character" either, only a character constant whose value
(of integer type) corresponds to the appropriate character.)

I don't think that the OP uses a multibyte character sert. When he has
an single byte character set then the paragraph above is meaningless.
 
T

The Real OS/2 Guy

When I use:

printf("%c\n", 'EOF');

It prints 'F', is it suppose to print that or am I invoking undefined behavior?

I'm happy to have a compiler that will give a diagnostic when the
locale is not set to a multibyte character set, but uses a single byte
one.
 
T

The Real OS/2 Guy

It is, however, a character constant.

The Standard says: "An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in 'x' or 'ab'."

Does you know the difference between multibyte and single byte
chararer sets?
So 'a' is not a character, then?

It is.
(Hint: 'a' is of type int, not char.)
It gets converted implicity to an int but it is none, else it were
impossible to assign it to an char without diagnostic.
 
T

The Real OS/2 Guy

The said:
No, 'abc' or 'EOF' or 'BAD' is NOT a character. A character is a
single char, not a sequence of chars. A sequence of chars is known a
string, but a string must be in double quotes. So the compiler will
throw a diagnistic.


That must come as a shock to the guys who wrote the Standard:


[#2] An integer character constant is a sequence of one or
more multibyte characters enclosed in single-quotes, as in
'x' or 'ab'. A wide character constant is the same, except
prefixed by the letter L. With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.
Why? Read it carefully! Get be informed on the difference between
multibyte and single byte character sets.
A multibyte character set uses multiple bytes to show a single char. A
singe byte character set only one.
 
I

Irrwahn Grausewitz

I don't think that the OP uses a multibyte character sert. When he has
an single byte character set then the paragraph above is meaningless.

Which part of

[...] With a few exceptions detailed
later, the elements of the sequence are any members of the
source character set; they are mapped in an implementation-
defined manner to members of the execution character set.

do you consider meaningless???


--
do not write: void main(...)
do not use gets()
do not cast the return value of malloc()
do not fflush( stdin )
read the c.l.c-faq: http://www.eskimo.com/~scs/C-faq/top.html
 
I

Irrwahn Grausewitz

The Real OS/2 Guy said:
It gets converted implicity to an int but it is none, else it were
impossible to assign it to an char without diagnostic.

This is simply wrong. Character constants in C are of type integer.
Lookup the standard on 'character constants'.


--
do not write: void main(...)
do not use gets()
do not cast the return value of malloc()
do not fflush( stdin )
read the c.l.c-faq: http://www.eskimo.com/~scs/C-faq/top.html
 
R

Richard Heathfield

The said:
Does you know the difference between multibyte and single byte
chararer sets?
Yes.


It is.

Right, 'a' is a character, and 'a' is an int. Therefore, a character is not
a single char.
It gets converted implicity to an int

No, it really really doesn't. It /is/ an int. AS USUAL, you sound very
confident but in fact you are utterly, utterly wrong. PLEASE understand
that you don't know as much about C as you thought you did. This is
something most of us go through when we start using this group; I know I
did, and lots of others here did too. But you seem to be slow to grasp
this. It's about time that you got a clue, and started to check your
opinions against an authoritative source before posting them.
but it is none, else it were
impossible to assign it to an char without diagnostic.

Nonsense.
 

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

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top