so even though I do:
typedef long int int_4
and I do sizeof(int_4) that will be the same wherever machine I am?? I guess not right
This is a discussion on unsigned int and unsigned long int within the C Programming forums, part of the General Programming Boards category; so even though I do: typedef long int int_4 and I do sizeof(int_4) that will be the same wherever machine ...
so even though I do:
typedef long int int_4
and I do sizeof(int_4) that will be the same wherever machine I am?? I guess not right
As tabstop mentions, no. That is why these typedefs exist in the first place. To map appropriate type into these typedefs so you can be sure about size.
You have to use lots of #ifs and stuff to make it right for every machine.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
oh okay by the way I have to slip in one unrelated question to this thread, say I have a code:
why doesn't it read directly from the command line when I typed in ./tiesto 0.5Code:#include <stdio.h> #include <stdlib.h> int main() { float number; scanf("%f", &number); printf("%f\n", number); return 0; }
it doesn't print 0.5 directly but it goes as I haven't typed in anything but after I typed it in again underneath it works...
scanf reads from the keyboard input, not the command line.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
well I thought I can do that.. in the previous assignment I have it works
Doesn't work that way.
You need to use a special main and get the arguments from there.
There's a tutorial on the site maybe?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Code:#ifdef NO_WAI_64_BITS typedef int_8 something; #elif NO_WAI_32_BITS typedef int_4 something; #endif
oh nevermind it works if I did a redirect from a file.. okay back to our topic again.. the point to all of this is this.. I want main to create a message say that I run the program and defining that it's on 64 bit machine but however it's on a 32 bit machine.. then I want to be able to print this error:
gcc -ansi -Wall -DMACHINE32 extract.c main.c -o main
ERROR: sizeof(int_u8) is not 8, it's 4
ERROR: sizeof(int_8) is not 8, it's 4
I think you're on the wrong track here.
The point of those typedefs is that uint64_t will always be 64-bit, whether or not it's a 32-bit machine or a 64-bit machine.
Same goes for any other typedef.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
okay so the type def should all be the same either for 32 bit machine or 64 bit machine??
The point is that if you use, for example, uint32_t, then
sizeof(uint32_t) on a 32-bit machine will give 4
and
sizeof(uint32_t) on a 64-bit machine will give 4.
The headers are full of #ifs and such to make sure this is the case.
And of course, each compiler has its own such header to make sure it uses the correct type to make it's the right size when compiled.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
The whole point with declaring typedefs (in this discussion) is that "you know what size the integer is". This helps in making sure for example that data structures are always the same size, data types match between different functions, etc.
In many cases, a regular "int", whatever size it happens to be, is a fine thing to use, but sometimes you need a type that matches some specific size, such as "32 bits", and if you want to be SURE that the type is exactly 32 bits, then you need a typedef that depends on the compiler/processor architecture, etc.
For example, a 64-bit compiler will make "long" a 64-bit number, but in a 32-bit compiler you need "long long" to make a 64-bit number.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.