Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > o/p problem

Reply
Thread Tools

o/p problem

 
 
=?iso-8859-1?q?Dag-Erling_Sm=F8rgrav?=
Guest
Posts: n/a
 
      12-30-2005
Lew Pitcher <(E-Mail Removed)> writes:
> - the width (sizeof()) of a character constant (hint: it isn't
> necessarily == 1)


in fact, it is guaranteed to be at least 2.

DES
--
Dag-Erling Smørgrav - http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      12-30-2005
(E-Mail Removed) (Dag-Erling Smørgrav) writes:
> Lew Pitcher <(E-Mail Removed)> writes:
>> - the width (sizeof()) of a character constant (hint: it isn't
>> necessarily == 1)

>
> in fact, it is guaranteed to be at least 2.


No, it isn't; consider CHAR_BIT==16, sizeof(int)==1.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
 
Flash Gordon
Guest
Posts: n/a
 
      12-30-2005
Dag-Erling Smørgrav wrote:
> Lew Pitcher <(E-Mail Removed)> writes:
>> - the width (sizeof()) of a character constant (hint: it isn't
>> necessarily == 1)

>
> in fact, it is guaranteed to be at least 2.


Not it isn't. A system with CHAR_BIT==16 and sizeof(int)==1 is perfectly
valid, and I've worked on embedded systems like this.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      12-30-2005
In article <(E-Mail Removed)>,
Keith Thompson <(E-Mail Removed)> wrote:
>(E-Mail Removed) (Dag-Erling Smørgrav) writes:
>> Lew Pitcher <(E-Mail Removed)> writes:
>>> - the width (sizeof()) of a character constant (hint: it isn't
>>> necessarily == 1)

>>
>> in fact, it is guaranteed to be at least 2.

>
>No, it isn't; consider CHAR_BIT==16, sizeof(int)==1.


Or how about a system on an 8 bit processor?
(I'm not sure about this - does the standard require ints to be at least 16
bits?)

 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      12-31-2005
Kenny McCormack said:

> (I'm not sure about this - does the standard require ints to be at least
> 16 bits?)


Yes.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
 
Reply With Quote
 
Dave Thompson
Guest
Posts: n/a
 
      01-04-2006
On Fri, 23 Dec 2005 11:54:45 -0700, Thad Smith <(E-Mail Removed)>
wrote:

> fidlee wrote:


> > char a='i';
> > printf("%d",a);


> > printf("%d",'i')


> > arent both character constants here??

>
> Yes, 'i' is a character constant in both cases, but it has type int. In
> the first case you are assigning it to a type char, possibly signed
> (implementation-defined), then converting the type char to int. In the
> second case, you are not converting to type char. If your char type is
> signed and (char)'i' is negative (depends on the character set and
> number of bits in a byte), you can get different values printed.
>

True for characters in general, but the characters required by the
standard in the basic execution character set, including a-z A-Z 0-9,
must have positive values when stored in (plain) char, whether that
"is" signed or unsigned. (Except zero for the null character.)

> In your situation, I suspect that there are other reasons that are not
> visible in the snippets you posted.


That did in fact turn out to be the case elsethread.
- David.Thompson1 at worldnet.att.net
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem problem problem :( Need Help Mike ASP General 2 05-11-2004 08:36 AM



Advertisments