473,413 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

Character Constants

Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.

#include<stdio.h>
int main(void)
{
char a='Abbc';
printf("%c",a);

return 0;
}

Please explain how the initialization is interpreted,on compilation it
gives a warning "multi-character character constant" but runs without
error also possibly the last character within the single quotes is
being stored in a.

Feb 21 '06 #1
23 3143
I got an error message when compile it in TC2.0
Error: Character constant too long in function main

Feb 21 '06 #2
Akhil wrote:
char a='Abbc'; Please explain how the initialization is interpreted,


The initialization is interpreted
any way that the compiler wants to.
The C standard doesn't define it.

--
pete
Feb 21 '06 #3
Akhil wrote:
Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.

#include<stdio.h>
int main(void)
{
char a='Abbc';
printf("%c",a);

return 0;
}

Please explain how the initialization is interpreted,on compilation it
gives a warning "multi-character character constant" but runs without
error also possibly the last character within the single quotes is
being stored in a.


For explanation of initialisation, refer to your compiler documentation,
as Standard says it's implementation defined.

As for the warning, your compiler is just being nice, letting you know
that you may be doing something you don't want. Mine also tells me that
implicit conversion has overflown.
--
BR, Vladimir

I am a friend of the working man, and I would rather be his friend
than be one.
-- Clarence Darrow

Feb 21 '06 #4
"Akhil" <ak*************@gmail.com> writes:
Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.
A character constant is of type int; for example,
sizeof('x') == sizeof(int). If sizeof(int) happens to be 4,
a character constant specifies a 4-byte value.
#include<stdio.h>
int main(void)
{
char a='Abbc';
printf("%c",a);

return 0;
}

Please explain how the initialization is interpreted,on compilation it
gives a warning "multi-character character constant" but runs without
error also possibly the last character within the single quotes is
being stored in a.


C99 6.4.4.4p10:

The value of an integer character constant containing more than
one character (e.g., 'ab'), or containing a character or escape
sequence that does not map to a single-byte execution character,
is implementation-defined.

So 'Abbc' has some implementation-defined value of type int. Using
that value to initialize a variable of type char requires a conversion
from int to char. If char happens to be unsigned, the conversion is
well defined; if char is signed, the result of the conversion is
implementation-defined (or it can raise an implementation-defined
signal, but that's not likely).

Try changing a from a char to an int and displaying the value in
hexadecimal:

int a = 'Abbc';
printf("a = 0x%x\n", a);

On one implementation, I get

a = 0x41626263

which corresponds to the ASCII values of the individual characters
'A', 'b', 'b', and 'c'. Assigning that value to a char happens to
give you the low-order 8 bits, the value of 'c'. All of this,
including the use of ASCII, is implementation-defined; you shouldn't
depend on any of it if you care at all about portability.

Incidentally, you need a '\n' after you print the value; otherwise
your output may not appear.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 21 '06 #5
>
C99 6.4.4.4p10:

The value of an integer character constant containing more than
one character (e.g., 'ab'), or containing a character or escape
sequence that does not map to a single-byte execution character,
is implementation-defined.


keith, can you recommend me an online easy to navigate web source for the
C standards please.

thanks

r
Feb 21 '06 #6
"Richard G. Riley" <rg***********@gmail.com> writes:
keith, can you recommend me an online easy to navigate web source for the
C standards please.


There is none, because the C standard is non-free. If you want
the standard, you have to buy it from a standards body. It is
$18 as a PDF from ANSI.
--
"Programmers have the right to be ignorant of many details of your code
and still make reasonable changes."
--Kernighan and Plauger, _Software Tools_
Feb 21 '06 #7
On 2006-02-21, Ben Pfaff <bl*@cs.stanford.edu> wrote:
"Richard G. Riley" <rg***********@gmail.com> writes:
keith, can you recommend me an online easy to navigate web source for the
C standards please.


There is none, because the C standard is non-free. If you want
the standard, you have to buy it from a standards body. It is
$18 as a PDF from ANSI.


Great, thanks : I found it. I guess they have to earn a crust too.

--
Remove evomer to reply
Feb 21 '06 #8
Richard G. Riley wrote:

On 2006-02-21, Ben Pfaff <bl*@cs.stanford.edu> wrote:
"Richard G. Riley" <rg***********@gmail.com> writes:
keith, can you recommend me an online easy to navigate web source for the
C standards please.


There is none, because the C standard is non-free. If you want
the standard, you have to buy it from a standards body. It is
$18 as a PDF from ANSI.


Great, thanks : I found it. I guess they have to earn a crust too.


Here's some drafts.
http://rm-f.net/~orange/devel/specifications/

The C89 standard is a little more expensive.

--
pete
Feb 21 '06 #9
Akhil a écrit :
Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.

#include<stdio.h>
int main(void)
{
char a='Abbc';


Undefined behavior. You're dead.

--
C is a sharp tool
Feb 21 '06 #10
Richard G. Riley a écrit :
keith, can you recommend me an online easy to navigate web source for the
C standards please.


Here is a free downloadable PDF. It's very close to the standard.

http://www.open-std.org/jtc1/sc22/wg...docs/n1124.pdf

You can get the genuine standard from http://webstore.ansi.org for 20 USD.

--
C is a sharp tool
Feb 21 '06 #11
Emmanuel Delahaye wrote:
Akhil a écrit :
Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.

#include<stdio.h>
int main(void)
{
char a='Abbc';


Undefined behavior. You're dead.


In what way? I can only think of the C99 case where the implementation
defined int constant is outside the range of char and an implementation
defined signal is raised. But such an implementation is likely be
commercially unprofitable.

--
Peter

Feb 21 '06 #12
On 2006-02-21, Peter Nilsson <ai***@acay.com.au> wrote:
Emmanuel Delahaye wrote:
Akhil a écrit :
> Since a character constant is an int value represented as a character
> in single quotes,so it is treated as a 1 byte integer now look at the
> following snippet.
>
> #include<stdio.h>
> int main(void)
> {
> char a='Abbc';


Undefined behavior. You're dead.


In what way? I can only think of the C99 case where the implementation
defined int constant is outside the range of char and an implementation
defined signal is raised. But such an implementation is likely be
commercially unprofitable.


Some people here have a bad habit as using "undefined" as a catch-all
for "undefined, implementation-defined, unspecified, or exceeds a
minimum maximum limit"
Feb 21 '06 #13

"pete" <pf*****@mindspring.com> wrote in message
news:43***********@mindspring.com...
Richard G. Riley wrote:

On 2006-02-21, Ben Pfaff <bl*@cs.stanford.edu> wrote:
"Richard G. Riley" <rg***********@gmail.com> writes:

> keith, can you recommend me an online easy to navigate web source for the> C standards please.

There is none, because the C standard is non-free. If you want
the standard, you have to buy it from a standards body. It is
$18 as a PDF from ANSI.

<snip>

A 554 page Adobe .pdf titled "International Standard ISO/IEC 9899 Second
Edition 1999-12-01" containing the text ISO/IEC 9899:1999(E) and official
ISO/IEC TM's is easily found with Google or Yahoo. At the very end, it also
lists a price of ICS 35.060 based on 537 pages...

Rod Pemberton

PS. I'm not encouraging theft. Just stating the facts.

Sony Corp. v. Universal City Studios
"...use of a copyrighted work is noncommercial, defeating a fair use defense
requires 'proof either that the particular use is harmful, or that if it
should become widespread, it would adversely affect the potential market for
the copyrighted work.'"

Feist Publications, Inc. v. Rural Tel. Serv. Co
"The primary objective of copyright is not to reward the labor of authors,
but 'to promote the Progress of Science and useful Arts.' . . . To this end,
copyright assures authors the right to their original expression, but
encourages others to build freely upon the ideas and information conveyed by
a work."

Feb 21 '06 #14
On Tue, 21 Feb 2006 16:41:42 -0500, "Rod Pemberton"
<do*********@sorry.bitbucket.cmm> wrote:

"pete" <pf*****@mindspring.com> wrote in message
news:43***********@mindspring.com...
Richard G. Riley wrote:
>
> On 2006-02-21, Ben Pfaff <bl*@cs.stanford.edu> wrote:
> > "Richard G. Riley" <rg***********@gmail.com> writes:
> >
> >> keith, can you recommend me an online easy to navigate web source forthe > >> C standards please.
> >
> > There is none, because the C standard is non-free. If you want
> > the standard, you have to buy it from a standards body. It is
> > $18 as a PDF from ANSI.
>
<snip>

A 554 page Adobe .pdf titled "International Standard ISO/IEC 9899 Second
Edition 1999-12-01" containing the text ISO/IEC 9899:1999(E) and official
ISO/IEC TM's is easily found with Google or Yahoo. At the very end, it also
lists a price of ICS 35.060 based on 537 pages...

Rod Pemberton

PS. I'm not encouraging theft. Just stating the facts.

Sony Corp. v. Universal City Studios
"...use of a copyrighted work is noncommercial, defeating a fair use defense
requires 'proof either that the particular use is harmful, or that if it
should become widespread, it would adversely affect the potential market for
the copyrighted work.'"


I've seen the decision. It really has nothing to do with illegal
copying of the standard (or any other work.) No competent lawyer would
bother trying to contend that copying the entire work is "fair use."

Even the snippet you quote says "... if it should become widespread,
it would adversely affect the potential market for the copyrighted
work." which is certainly the case here. Fair use would be, e.g., the
quoting of a particular passage from the standard, which even if
widespread, would not affect the sales of the work as a whole.
Feist Publications, Inc. v. Rural Tel. Serv. Co
"The primary objective of copyright is not to reward the labor of authors,
but 'to promote the Progress of Science and useful Arts.' . . . To this end,
copyright assures authors the right to their original expression, but
encourages others to build freely upon the ideas and information conveyed by
a work."

Of course. That's why the author of a book about C can, for example,
provide explanations and examples illustrating and clarifying what the
standard says. It doesn't mean that he can insert portions of the
standard verbatim in his book without acquiring permission from the
copyright holder.

--
Al Balmer
Sun City, AZ
Feb 21 '06 #15
Emmanuel Delahaye <em***@YOURBRAnoos.fr> writes:
Akhil a écrit :
Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.
#include<stdio.h>
int main(void)
{
char a='Abbc';


Undefined behavior. You're dead.


No, just implementation-defined. You're non-portable.

:-)

-Micah
Feb 21 '06 #16
Emmanuel Delahaye <em***@YOURBRAnoos.fr> writes:
Akhil a écrit :
Since a character constant is an int value represented as a character
in single quotes,so it is treated as a 1 byte integer now look at the
following snippet.
#include<stdio.h>
int main(void)
{
char a='Abbc';


Undefined behavior. You're dead.


The behavior is implementation-defined, not undefined.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 21 '06 #17
"Peter Nilsson" <ai***@acay.com.au> writes:
Emmanuel Delahaye wrote:
Akhil a écrit :
> Since a character constant is an int value represented as a character
> in single quotes,so it is treated as a 1 byte integer now look at the
> following snippet.
>
> #include<stdio.h>
> int main(void)
> {
> char a='Abbc';


Undefined behavior. You're dead.


In what way? I can only think of the C99 case where the implementation
defined int constant is outside the range of char and an implementation
defined signal is raised. But such an implementation is likely be
commercially unprofitable.


Raising an implementation-defined signal isn't undefined behavior
either (no nasal demons).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <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.
Feb 21 '06 #18
On 2006-02-21, Rod Pemberton <do*********@sorry.bitbucket.cmm> wrote:
A 554 page Adobe .pdf titled "International Standard ISO/IEC 9899 Second
Edition 1999-12-01" containing the text ISO/IEC 9899:1999(E) and official
ISO/IEC TM's is easily found with Google or Yahoo. At the very end, it also
lists a price of ICS 35.060 based on 537 pages...


What is an "ICS", anyway? It doesn't seem to be an ISO 4217 code.

[I actually found this same file, while I was looking for N1124. not
having the term "N1124" to search for at the time, I just entered "c99
pdf" and crossed my fingers]
Feb 21 '06 #19

In article <32********************************@4ax.com>, Al Balmer <al******@att.net> writes:

No competent lawyer would
bother trying to contend that copying the entire work is "fair use."


Nit: Under USC Title 17 (US Federal copyright law), at least prior to
WIPO, archival copying of an entire work is fair use. (Of course, the
original copy may still be a violation.) But I agree that Rod's legal
argument is nonsense.

--
Michael Wojcik mi************@microfocus.com

Cooperation is just like two pagodas, one hardware and one software.
-- Wen Jiabao
Feb 23 '06 #20
On 2006-02-23, Michael Wojcik <mw*****@newsguy.com> wrote:

In article <32********************************@4ax.com>, Al Balmer <al******@att.net> writes:

No competent lawyer would
bother trying to contend that copying the entire work is "fair use."


Nit: Under USC Title 17 (US Federal copyright law), at least prior to
WIPO, archival copying of an entire work is fair use. (Of course, the
original copy may still be a violation.) But I agree that Rod's legal
argument is nonsense.


You do have to consider the landscape though - It's arguable that there
is an assumption that anything posted on the internet that's not behind
a login / credit card / etc is free to load in your web browser and
view, just like there is an assumption in the real that you can enter
any land that does not have a fence or any "no trespassing" signs
posted.

For another example: you included an excerpt from Al Balmer's
copyrighted work and I in turn included that excerpt and the entire text
of your own in this message. Under the strict interpretation of
copyright law that has been put forward in this thread, this would have
been illegal. I guess all the google groups users are really just trying
to avoid liability for copyright violation.
Feb 23 '06 #21
On 23 Feb 2006 17:11:54 GMT, Jordan Abel <ra*******@gmail.com> wrote:
On 2006-02-23, Michael Wojcik <mw*****@newsguy.com> wrote:

In article <32********************************@4ax.com>, Al Balmer <al******@att.net> writes:

No competent lawyer would
bother trying to contend that copying the entire work is "fair use."
Nit: Under USC Title 17 (US Federal copyright law), at least prior to
WIPO, archival copying of an entire work is fair use. (Of course, the
original copy may still be a violation.) But I agree that Rod's legal
argument is nonsense.


You do have to consider the landscape though - It's arguable that there
is an assumption that anything posted on the internet that's not behind
a login / credit card / etc is free to load in your web browser and
view, just like there is an assumption in the real that you can enter
any land that does not have a fence or any "no trespassing" signs
posted.

For another example: you included an excerpt from Al Balmer's
copyrighted work and I in turn included that excerpt and the entire text
of your own in this message. Under the strict interpretation of
copyright law that has been put forward in this thread, this would have
been illegal.


Probably not, for two reasons - including excerpts or even entire
short texts as part of a discussion or review, or for illustration,
falls under fair use, and the terms of service for your Internet
provider likely include a weakening of your copyrights, so as to allow
them to post your messages in a public forum, and to archive them.

OTOH, if someone collects a bunch of articles written here, and
republishes them as a book without getting permission from all the
authors, that's illegal. Even if you publish it on the Internet :-)

Having said that, if you distributed it for free, you could be made to
stop, but there would be little monetary penalty.
I guess all the google groups users are really just trying
to avoid liability for copyright violation.


--
Al Balmer
Sun City, AZ
Feb 23 '06 #22
On 2006-02-23, Al Balmer <al******@att.net> wrote:
OTOH, if someone collects a bunch of articles written here, and
republishes them as a book without getting permission from all the
authors, that's illegal. Even if you publish it on the Internet :-)


So where does google stand on that issue? (Sorry, I had to ask)
Though... I bet if it was tested, the X-no-archive header would provide
a basis for a ruling similar to the recent robots.txt decision. Local
custom [the "locality" here being the internet] clearly has some
influence on the interpretation of the law.
Feb 23 '06 #23
On Thu, 23 Feb 2006 10:58:45 -0700, Al Balmer <al******@att.net>
wrote:
On 23 Feb 2006 17:11:54 GMT, Jordan Abel <ra*******@gmail.com> wrote:
On 2006-02-23, Michael Wojcik <mw*****@newsguy.com> wrote:

In article <32********************************@4ax.com>, Al Balmer <al******@att.net> writes:

BTW, this is getting really off-topic for c.l.c., so I'll try to
restrain myself in future.

--
Al Balmer
Sun City, AZ
Feb 23 '06 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Job Lot | last post by:
I have an enumeration as follows Public Enum Delimiters Tab Semicolon Comma Space End Enum How can I return character equivalent of the elements in the enumeration?
20
by: adityavasishth | last post by:
hi all, Characters are basically implemented via integers,ex : '\0' is 0.But integers requires 2 bytes and the characters require only 1 byte.So,can anybody please tell me that how the...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
3
by: Maileen | last post by:
Hi, I would like to know how can i do if i want to display the copyright character (the C into a circle) into my About window ? thanks a lot, Maileen
3
by: myjunk12 | last post by:
Hi, In C++, I could create an enum like this: enum Position { Quarterback = 'QB', LeftCornerback = 'LCB', RightOutsideLinebacker = 'ROLB' }
15
by: wizardyhnr | last post by:
i want to try ANSI C99's unicode fuctions. so i write a test program. the function is simple, but i cannot compile it with dev c++ 4.9.9.2 under windows xp sp2, since the compiler always think that...
2
by: Kavya | last post by:
In C, the character constants are of type int but in C++ character constant are of type char. Why is there an incompatibilty here when C++ was designed to be a lot compatible to C. Shouldn't such...
9
by: jraul | last post by:
1) Am I correct that C++ does not have a defined character set? In particular, a platform might not use the ASCII character set? 2) C++ supports wchar_t types. But again, this has no defined...
10
by: aarklon | last post by:
Hi all, what exactly is the purpose of multi-character constant..???
19
by: bowlderyu | last post by:
Hello, all. If a struct contains a character strings, there are two methods to define the struct, one by character array, another by character pointer. E.g, //Program for struct includeing...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.