Re: is order urgent doubt
- From: jacob navia <jacob@xxxxxxxxxx>
- Date: Tue, 03 Jun 2008 08:21:37 +0200
new to c wrote:
Keith Thompson wrote:
new to c <non@xxxxxxxxxxxx> writes:Bartc wrote:You mean "the same problem"."new to c" <non@xxxxxxxxxxxx> wrote in message news:6468955.gypaU67uLZ@xxxxxxxxxxxxxxxxProblem equal.
I write big international program and need double integer. Why size isTry: long long int
different when other order?
If you're lucky, this will have size 8.
int i;You mean "important" or "significant", not "urgent".
i = sizeof(long long int);
printf("%i", i);
i = sizeof(long int long);
printf("%i", i);
i = sizeof(int long long);
printf("%i", i);
First code warn nothing and print 8.
Second code warn "multiple use of 'long'" and print 4.
Third code warm "multiple use of 'longlong'" and print 8.
Why is different number? Is order urgent?
Assuming the code you posted is the code you actually compiled and
ran, it appears that your compiler is buggy. What compiler are you
using?
Please post a small complete program that exhibits the problem.
Copy-and-paste the entire exact program; don't re-type it or summarize
it. Show us the compiler's warnings and the program's output
(copy-and-paste them as well).
Change each "%i" to "%i\n" (or "%d\n", which is equivalent but more
common).
Not all compilers support "long long", but most do (the feature was
added in C99, but a lot of pre-C99 compilers support it as an
extension).
All three chunks of code are exactly equivalent. For an integer type,
the order of the keywords is not significant; all of "long long int",
"long int long", and "int long long" mean exactly the same thing. If
your compiler is treating them differently, then there's a bug in your
compiler. (I think we've already told you this.)
As a matter of programming style, messing around with the order of the
keywords isn't a good idea. A properly working compiler won't care,
but using an order other than the usual one will just make your code
(slightly) harder to read, with no real benefit. (It's been argued
that using, for example, "long unsigned" rather than "unsigned long"
helps to remind you to use "%lu" rather than "%ul" for printf; I don't
find that argument convincing.)
Also, if you use the more common orderings, it's likely you can avoid
triggering your compiler's bugs (though I'd recommend finding a
compiler that works properly).
I use wedit IDE.
I write this code :
#include <stdio.h>
int main(void)
{
int i;
i = sizeof(long int);
printf("sizeof(long int): %d\n", i);
i = sizeof(int long);
printf("sizeof(int long): %d\n", i);
i = sizeof(double int);
printf("sizeof(double int): %d\n", i);
i = sizeof(int double);
printf("sizeof(int double): %d\n", i);
i = sizeof(long long int);
printf("sizeof(long long int): %d\n", i);
i = sizeof(long int long);
printf("sizeof(long int long): %d\n", i);
i = sizeof(int long long);
printf("sizeof(int long long): %d\n", i);
return 0;
}
Compiler warn
Warning c:\New_Folder\Test.c: 3 old-style definition for 'main'
Warning c:\New_Folder\Test.c: 3 missing prototype for 'main'
Warning c:\New_Folder\Test.c: 12 multiple use of 'int'
Warning c:\New_Folder\Test.c: 15 multiple use of 'double'
Warning c:\New_Folder\Test.c: 21 multiple use of 'long'
Warning c:\New_Folder\Test.c: 24 multiple use of 'longlong'
Compilation + link time 24.2 sec, Return code: 0
Code print
sizeof(long int): 4
sizeof(int long): 4
sizeof(double int): 4
sizeof(int double): 8
sizeof(long long int): 8
sizeof(long int long): 4
sizeof(int long long): 8
Hi.
I am the author of lcc-win. I have changed the warning messages to a
clearer one. Now your program produces the following warnings:
Warning td.c: 12 multiple types in a declaration. Last will be used: 'int'
Warning td.c: 15 multiple types in a declaration. Last will be used: 'double'
Warning td.c: 21 multiple types in a declaration. Last will be used: 'long'
Warning td.c: 24 multiple types in a declaration. Last will be used: 'longlong'
Maybe this will clarify what lcc-win is doing.
--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
.
- Follow-Ups:
- Re: is order urgent doubt
- From: Flash Gordon
- Re: is order urgent doubt
- From: Keith Thompson
- Re: is order urgent doubt
- References:
- is order urgent doubt
- From: new to c
- Re: is order urgent doubt
- From: Keith Thompson
- Re: is order urgent doubt
- From: new to c
- Re: is order urgent doubt
- From: Bartc
- Re: is order urgent doubt
- From: new to c
- Re: is order urgent doubt
- From: Keith Thompson
- Re: is order urgent doubt
- From: new to c
- is order urgent doubt
- Prev by Date: Re: storing data in file instead of memory
- Next by Date: Re: Determine the size of malloc
- Previous by thread: Re: is order urgent doubt
- Next by thread: Re: is order urgent doubt
- Index(es):
Relevant Pages
|