ansi c compiler character encoding

A

Andreas Lundgren

Hi!

Is it determined that the C standard compiler always encode characters
with the same character excoding? If for example the functions Foo and
Bar are compiled by different compilers, is it unambiguous how to
interpret the character string in Bar?

Does string.h expect a specific string format?

void Foo(void)
{
char myTextString[11] = "stuvxyzåäö";
Bar(myTextString);
}

void Bar(char* inp)
{
What character set to expect?
}
 
K

Keith Thompson

Andreas Lundgren said:
Is it determined that the C standard compiler always encode characters
with the same character excoding? If for example the functions Foo and
Bar are compiled by different compilers, is it unambiguous how to
interpret the character string in Bar?

Does string.h expect a specific string format?

void Foo(void)
{
char myTextString[11] = "stuvxyzåäö";
Bar(myTextString);
}

void Bar(char* inp)
{
What character set to expect?
}

No.

But if the two compilers are being used on the same system, it's very
likely that they'll use the same encoding. Since you're calling one
function from the other, presumably you're using the compilers on the
same system and linking the resulting code into a single executable or
equivalent.

Typically a given operating system will impose representations for
certain things. Though this is outside the scope of the C standard,
it's in the best interest of compiler writers to make their generate
code work and play well with that of other compilers. (For example, a
C compiler for Linux that generates code that's incompatible with code
generated by gcc wouldn't be very useful.)

This goes far beyond character set issues and includes things like
integer and floating-point type representations and function calling
conventions.

Your later followup suggests that you're concerned about some
real-world situation, presumably on some specific system. You should
ask in a newsgroup that deals with that system.
 
J

Jens Thoms Toerring

Keith Thompson said:
Andreas Lundgren said:
Is it determined that the C standard compiler always encode characters
with the same character excoding? If for example the functions Foo and
Bar are compiled by different compilers, is it unambiguous how to
interpret the character string in Bar?

Does string.h expect a specific string format?

void Foo(void)
{
char myTextString[11] = "stuvxyzåäö";
Bar(myTextString);
}

void Bar(char* inp)
{
What character set to expect?
}

But if the two compilers are being used on the same system, it's very
likely that they'll use the same encoding. Since you're calling one
function from the other, presumably you're using the compilers on the
same system and linking the resulting code into a single executable or
equivalent.

Is it actually a question about the compiler at all? As far as
I can see the compiler will happily create a string literal with
whatever there is in the string, not caring a bit about the en-
coding of the string. I guess the problem is much more one of
how the source files are generated and the expectations of the
output medium.

Consider the case of using one editor for the first file, set
to output files in e.g. one of the different (and incompatible)
russian extended ASCII code pages, and the second file genera-
ted with another editor, set to output in a different encoding.
Even if you use the same compiler this should lead to trouble.
And if then the terminal that receives the output of the pro-
gram is set to a third encoding it becomes a complete mess;-)

Regards, Jens
 
D

Daniel Molina Wegener

Hi!

Is it determined that the C standard compiler always encode characters
with the same character excoding? If for example the functions Foo and
Bar are compiled by different compilers, is it unambiguous how to
interpret the character string in Bar?

No, it does not depends on the compiler...
Does string.h expect a specific string format?

void Foo(void)
{
char myTextString[11] = "stuvxyzåäö";

Here, instead of char, try with wchar_t and
related functions if you are using unicode
for your messages and your .c files
Bar(myTextString);

}

void Bar(char* inp)
{
What character set to expect?

Thats depends on the user environment, but if the
user environments is using unicode, you can expect no
more than an array of bytes, other case is with
wchar_t and related functions...

Regards,
DMW
 
J

jameskuyper

Daniel said:
Hi!

Is it determined that the C standard compiler always encode characters
with the same character excoding? If for example the functions Foo and
Bar are compiled by different compilers, is it unambiguous how to
interpret the character string in Bar?

No, it does not depends on the compiler...
Does string.h expect a specific string format?

void Foo(void)
{
char myTextString[11] = "stuvxyz���";

Here, instead of char, try with wchar_t and
related functions if you are using unicode
for your messages and your .c files

Whether or not wchar_t has anything to do with unicode depends upon
the compiler; the standard makes no such requirement. When it does,
the way in which you can take advantage of that fact depends upon the
compiler as well.
 
F

Flash Gordon

Daniel Molina Wegener wrote, On 18/08/08 18:29:
No, it does not depends on the compiler...

You are wrong. See the replies others posted before you for details.
Does string.h expect a specific string format?

void Foo(void)
{
char myTextString[11] = "stuvxyzåäö";

Here, instead of char, try with wchar_t and
related functions if you are using unicode
for your messages and your .c files
Bar(myTextString);

}

void Bar(char* inp)
{
What character set to expect?

Thats depends on the user environment,

Wrong. It depends on what the function is written to expect and
(assuming the function expects a simple C string, which is likely) on
the encoding the implementation expects.

Actually, the expected encodings for standard C library functions which
handle strings and characters can be changed at run-time using the
setlocale() function, so it could also depend on what the program has
done before calling this function.
but if the
user environments is using unicode, you can expect no
more than an array of bytes,

Not necessarily.
other case is with
wchar_t and related functions...

For a start, an array of wchar_t is not simply an array of bytes.
 
D

Dik T. Winter

> A simple example may be the letter =D6 that in ASCII is represented by
> the number 153, but in ISO-8859-1 and Unicode is represented by the
> number 214.

That letter is not represented in ASCII. ASCII contains the code points
0 to 127, no more.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top