unsigned long long in GCC?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:unsigned long long in GCC?

Post by Solar »

paulbarker wrote:
It's still valid C++ to use 'struct mmap' but in practice it is never used.
Ah, OK - "never used" happens to exclude any C++ code I've worked on so far. ;)
Every good solution is obvious once you've found it.
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:unsigned long long in GCC?

Post by df »

why not include stdint.h and use uint64_t ??
-- Stu --
bakery2k

Re:unsigned long long in GCC?

Post by bakery2k »

Candy wrote: AFAIK, you always need to say:

Code: Select all

typedef struct {

} xyz;
, both in C and C++, since they're based on the same language. For classes this typedef is implicit. At least, that's what I know.
Almost. In C++, for both classes and structs, the typedef is implicit.
B.E

Re:unsigned long long in GCC?

Post by B.E »

What is the actual line you print this out. what i mean is, is it like this

Code: Select all

printf("%d\n",sizeof(struct asd));
or this

Code: Select all

printf(sizeof(struct asd));
evincarofautumn

Re:unsigned long long in GCC?

Post by evincarofautumn »

I don't know if this has anything to do with it, but I've seen that some [tt]printf[/tt]s don't support 64-bit integers properly; printing, for example, 0x0000 0000 0000 0014 (20) might produce only the first 32 bits, 0x0000 0000 (0), because [tt]%i[/tt] or [tt]%d[/tt] will only see 32-bit values on the stack. Something similar may be happening with your [tt]printf[/tt]; if any values that follow in the arg list are also borked, then that's my diagnosis.

Hope this helps.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:unsigned long long in GCC?

Post by Solar »

evincarofautumn wrote: ...because [tt]%i[/tt] or [tt]%d[/tt] will only see 32-bit values on the stack.
*cough*

Of course will %i and %d only see 32-bot-values on the stack. That is why a compliant printf supports %ld and %lld for long and long long...
Every good solution is obvious once you've found it.
User avatar
spix
Member
Member
Posts: 128
Joined: Mon Jun 26, 2006 8:41 am
Location: Millicent, South Australia
Contact:

Re:unsigned long long in GCC?

Post by spix »

Something similar may be happening with your printf; if any values that follow in the arg list are also borked, then that's my diagnosis.
I misunderstood this too, what viral is trying to do is print the sizeof a long long which is only 8 bytes and the structure is as someone else mentioned is 20 bytes, so %d will easily handle it.
Kemp

Re:unsigned long long in GCC?

Post by Kemp »

Yeah, he's printing the size of them, not the values, and if the size couldn't fit in a 32-bit variable then we have slightly more problems :P
viral

Re:unsigned long long in GCC?

Post by viral »

Yeah, he's printing the size of them, not the values, and if the size couldn't fit in a 32-bit variable then we have slightly more problems
Ya I dont have a structure whos size is more than 4GB.
paulbarker

Re:unsigned long long in GCC?

Post by paulbarker »

I'm guessing you're using the gcc that comes precompiled for your system

What happens if you compile a really simple program in c++, which has the structure definition and a main function which prints the size the struct and does *nothing* else? If that fails, try building your own gcc (maybe even as a cross-compiler - see the osfaq).

If you are using a gcc you build yourself, try rebuilding it and if possible run 'make check' before installing - the c testsuite should catch this sort of problem.

Another trick is to use 'gcc -S' on the source file to get assembly language output, or 'gcc -E' to make sure it isn't a weird pre-processing definition which is ruining the code.

Try printing the size of a packed structure (see the gcc manual).

And try everything else you can think of to isolate what is causing this bug because it is very, very strange.
viral

Re:unsigned long long in GCC?

Post by viral »

Hi..
Thanks for all those replies....
And try everything else you can think of to isolate what is causing this bug because it is very, very strange.
Ya the bug is really very very strange and thts why I change my code from long long to simple unsigned int.

Now its working nicely as no long long manipulation needed.... I dont see any benifits in wasting time to debug that ugly long long issue.. better I switch to more general format..
evincarofautumn

Re:unsigned long long in GCC?

Post by evincarofautumn »

Ya I dont have a structure whos size is more than 4GB.
I sorely misworded that post. ;D
Post Reply