char double doubt

C

cafetiere

I have double doubt.I write international program and my program
process international characters.But assign big character is half
lost.Then I write test program and program print is 1 but big
character need 2 bytes or 4 bytes.

#include <stdio.h>
int main (void)
{
double char ch= L'x';
printf ("sizeof(ch): %d\n", sizeof(ch));
return 0;
}

Compiler print no warn.Is compile problem?I use win32.
 
K

Keith Thompson

cafetiere said:
I have double doubt.I write international program and my program
process international characters.But assign big character is half
lost.Then I write test program and program print is 1 but big
character need 2 bytes or 4 bytes.

#include <stdio.h>
int main (void)
{
double char ch= L'x';
printf ("sizeof(ch): %d\n", sizeof(ch));
return 0;
}

Compiler print no warn.Is compile problem?I use win32.

C doesn't use the name "double char" or "char double" for wide
characters. Instead, it uses "wchar_t", which is declared in
<stddef.h>; various utilities for dealing with wide characters are
declared in <wchar.h>.

Your compiler should have issued a diagnostic for the above program.
It appears that it's just silently ignoring the "double" keyword. I
suggest you contact the maintainer for the compiler you're using and
report this bug. (I think I know which compiler it is, but I won't
mention it.)
 
T

Three Headed Monkey

Keith said:
C doesn't use the name "double char" or "char double" for wide
characters. Instead, it uses "wchar_t", which is declared in
<stddef.h>; various utilities for dealing with wide characters are
declared in <wchar.h>.

Your compiler should have issued a diagnostic for the above program.
It appears that it's just silently ignoring the "double" keyword. I
suggest you contact the maintainer for the compiler you're using and
report this bug. (I think I know which compiler it is, but I won't
mention it.)

The world wants to know which compiler.
 
C

cafetiere

Richard said:
cafetiere said:


That's a syntax error. I think you mean:

wchar_t ch = L'x';


The compiler is required to produce a diagnostic message for the
syntax error indicated above. If it doesn't, you aren't invoking
the compiler in conforming mode (or it isn't a conforming
compiler).

Is bad compiler?
What is good compiler?
 
K

Keith Thompson

Three Headed Monkey said:
Keith said:
double char ch= L'x';
[...]

C doesn't use the name "double char" or "char double" for wide
characters. Instead, it uses "wchar_t", which is declared in
<stddef.h>; various utilities for dealing with wide characters are
declared in <wchar.h>.

Your compiler should have issued a diagnostic for the above program.
It appears that it's just silently ignoring the "double" keyword. I
suggest you contact the maintainer for the compiler you're using and
report this bug. (I think I know which compiler it is, but I won't
mention it.)

The world wants to know which compiler.

Ok, I saw the same problem with a recent version of lcc-win.
 
J

James Kuyper

cafetiere said:
Is bad compiler?
What is good compiler?

Almost all C compilers are non-conforming in their default mode. Most C
compilers have command line options that allow them to conform fully
with C90, but only a few have options that allow them to conform fully
with C99. A larger number have options that allow them to conform fairly
well to C99. However, if you don't know what those options are, you
probably aren't using your compiler in a conforming mode.

Good/bad and conforming/non-conforming are separate (though related)
issues. Having at least an optional mode in which it conforms to the
standard is one of the more important things that determine whether a
compiler is good, but ease of use, generation of efficient code, speed
of compilation, size of the compiled executable are among the many other
issues that are also relevant. A perfectly conforming compiler can also
be very bad.

Having said that - a compiler that allows you to use 'double char'
without issuing a diagnostic isn't much of a C compiler, even allowing
for the likelihood that you invoked it in a non-conforming mode.
 
R

Richard Bos

Three Headed Monkey said:
The world wants to know which compiler.

Take a flying guess. I can think of only two which _possibly_ could, and
one of those (i.e., gcc) definitely doesn't.

Richard
 
J

JosephKK

Is bad compiler?
What is good compiler?
Just my take:

bad compiler := seriously non-conformant, fails to implement 9 of 10
requirements of the standard.

good compiler := correctly implements 99 of 100 requirements of the
standars, extentions optional.

Notice the gap. Reality is gradient, not boolean.
.
 
B

Boon

cafetiere said:
I have double doubt.

Does this mean you are /very/ confused? :)
I write international program and my program
process international characters.But assign big character is half
lost.Then I write test program and program print is 1 but big
character need 2 bytes or 4 bytes.

Compiler print no warn.Is compile problem?I use win32.

$ cat foo.c
#include <stdio.h>
int main(void)
{
double char ch = L'x';
printf("sizeof(ch): %d\n", sizeof(ch));
return 0;
}

$ gcc -Wall -Wextra -Werror -std=c89 -pedantic -O2 foo.c
foo.c: In function 'main':
foo.c:4: error: two or more data types in declaration specifiers
 
C

Coffee Pot

cafetiere said:
I have double doubt.I write international program and my program
process international characters.But assign big character is half
lost.Then I write test program and program print is 1 but big
character need 2 bytes or 4 bytes.

#include <stdio.h>
int main (void)
{
double char ch= L'x';
printf ("sizeof(ch): %d\n", sizeof(ch));
return 0;
}

Compiler print no warn.Is compile problem?I use win32.

That is all wrong. If you want to use big characters you use
char double not double char everybody knows that! Let me demonstrate...

#include <stdio.h>
void int main(void)
{
double char ch1;
char double ch2;
printf("sizeof ch1: %lu\n", (unsigned long)sizeof ch1);
printf("sizeof ch2: %lu\n", (unsigned long)sizeof ch2);
return 0;
}


sizeof ch1: 1
sizeof ch2: 8
 
K

Keith Thompson

Coffee Pot said:
That is all wrong. If you want to use big characters you use
char double not double char everybody knows that! Let me demonstrate...

#include <stdio.h>
void int main(void)
{
double char ch1;
char double ch2;
printf("sizeof ch1: %lu\n", (unsigned long)sizeof ch1);
printf("sizeof ch2: %lu\n", (unsigned long)sizeof ch2);
return 0;
}


sizeof ch1: 1
sizeof ch2: 8

"Coffee Pot" is apparently trying to make a joke of some sort. For
the benefit of anyone who might take it seriously, both "double char"
and "char double" are illegal. (A note to "Coffee Pot": jokes are
usually funny.)
 

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,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top