Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Printing string constants

Reply
Thread Tools

Printing string constants

 
 
Ross
Guest
Posts: n/a
 
      06-30-2006
I have a quick question regarding printing string constants. When you
printf() a string constant, how are the characters encoded that get
sent to the standard output? Is it in the execution character set?

Thanks in advance.

 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      06-30-2006
"Ross" <(E-Mail Removed)> wrote
>I have a quick question regarding printing string constants. When you
> printf() a string constant, how are the characters encoded that get
> sent to the standard output? Is it in the execution character set?
>

That's right.
Normally C source is written in ASCII, and generally C programs use ASCII
internally as their execution set. A few years ago I would have said "most
machines are ASCII" but the concept of an "ASCII machine" has become a bit
fuzzier since then.
Occasionally you might have a C source, but compile for a machine with a
funny character set. So the source file

printf("Hello world\n");

contains the ASCII values 72, 101, 108, 108, etc, along with ASCII values
for the quote,34 paretheses 40, 41, and so on.

Our funny system uses 100 for A, 101 for B, 200 for a 201 for b and so on.
So when we compile, the string "Hello world\n" is laid out in memory as 107,
204, 211, 211 etc. These values are passed to printf(), and by some magic
the glyphs appear in shining pixels on the screen.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm


 
Reply With Quote
 
 
 
 
Barry Schwarz
Guest
Posts: n/a
 
      07-01-2006
On 30 Jun 2006 07:41:14 -0700, "Ross" <(E-Mail Removed)>
wrote:

>I have a quick question regarding printing string constants. When you
>printf() a string constant, how are the characters encoded that get
>sent to the standard output? Is it in the execution character set?
>

If by string constant you mean string literal, they are created at
compile time. I expect the compiler is required to convert them from
the compilation character set to the execution character set. On the
other hand, you can send any NUL-terminated array of char to printf
and it is up to whatever is on the other side of stdout to determine
what happens to each byte.


Remove del for email
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-01-2006
"Malcolm" <(E-Mail Removed)> writes:
> "Ross" <(E-Mail Removed)> wrote
>>I have a quick question regarding printing string constants. When you
>> printf() a string constant, how are the characters encoded that get
>> sent to the standard output? Is it in the execution character set?
>>

> That's right.
> Normally C source is written in ASCII, and generally C programs use ASCII
> internally as their execution set. A few years ago I would have said "most
> machines are ASCII" but the concept of an "ASCII machine" has become a bit
> fuzzier since then.

[...]

It depends on what you mean by "normally".

There are still machines that use the EBCDIC character set. C
programs on such machines are written in EBCDIC, and they generally
produce EBCDIC output. This is not common, and it's probably becoming
less common with the passage of years, but there's nothing abnormal
about it.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(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
 
Malcolm
Guest
Posts: n/a
 
      07-01-2006
"Keith Thompson" <(E-Mail Removed)> wrote
> "Malcolm" <(E-Mail Removed)> writes:
>
> It depends on what you mean by "normally".
>
> There are still machines that use the EBCDIC character set. C
> programs on such machines are written in EBCDIC, and they generally
> produce EBCDIC output. This is not common, and it's probably becoming
> less common with the passage of years, but there's nothing abnormal
> about it.
>

But it must happen that programmers who work with such machines regularly
take functions stored as ASCII text, for example in the comp.lang.c FAQ, and
expect them to work on their platform.

Anyway, what is the PC I am typing this at? Would you call it a Unicode
machine or an ASCII machine? Surely it is really an attribute of the program
that happens to be running at the time, in a modern system.
--
Buy my book 12 Common Atheist Arguments (refuted)
$1.25 download or $7.20 paper, available www.lulu.com/bgy1mm



 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      07-01-2006
Malcolm said:

> "Keith Thompson" <(E-Mail Removed)> wrote
>> "Malcolm" <(E-Mail Removed)> writes:
>>
>> It depends on what you mean by "normally".
>>
>> There are still machines that use the EBCDIC character set. C
>> programs on such machines are written in EBCDIC, and they generally
>> produce EBCDIC output. This is not common, and it's probably becoming
>> less common with the passage of years, but there's nothing abnormal
>> about it.
>>

> But it must happen that programmers who work with such machines regularly
> take functions stored as ASCII text, for example in the comp.lang.c FAQ,
> and expect them to work on their platform.


Yes. When they move those programs to their platform, it typically undergoes
a translation process (e.g. ASCII to EBCDIC). It's commonplace, and easy to
do, although the various flavours of EBCDIC make it slightly more
interesting if you have to write the conversion yourself. Normally, though,
a mainframe is accessed via terminal emulation software which knows how to
do the translation for you, in either direction.

> Anyway, what is the PC I am typing this at? Would you call it a Unicode
> machine or an ASCII machine? Surely it is really an attribute of the
> program that happens to be running at the time, in a modern system.


Right. Who cares? As long as there's a way to convert text to the relevant
character set, that's all that matters.



--
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
 
 
 
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
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 2 11-27-2010 12:12 PM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:52 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:50 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-21-2007 05:28 AM
brochure printing,online yearbook,printing,books printing,publishing elie Computer Support 0 08-18-2007 10:11 AM



Advertisments