Reading the following resource it says the size of an int/pointer can vary depending on the compiler:    Why is this?  I understand C defines only the min and max number of what a type should hold, but why would one compiler choose to set for example int to 2 bytes and another at 4? What would be the advantage of one over another?
69127
I'm looking for detailed information regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler.  But are there any standards for C++?  I'm using Visual Studio 2008 on a 32-bit architecture. Here is what I get:  char  : 1 byte short : 2 bytes int   : 4 bytes long  : 4 bytes float : 4 bytes double: 8 bytes   I tried to find, without much success, reliable information stating the sizes of char, short, int, long, double, float (and other types I didn't think of) under different architectures and compilers.
106074
Why doesn't Java include support for unsigned integers?    It seems to me to be an odd omission, given that they allow one to write code that is less likely to produce overflows on unexpectedly large input.    Furthermore, using unsigned integers can be a form of self-documentation, since they indicate that the value which the unsigned int was intended to hold is never supposed to be negative.    Lastly, in some cases, unsigned integers can be more efficient for certain operations, such as division.    What's the downside to including these?
981
How do I determine the size of my array in C?   That is, the number of elements the array can hold?
23330
I am trying to adapt an existing code to a 64 bit machine. The main problem is that in one function, the previous coder uses a void* argument that is converted into suitable type in the function itself. A short example:  void function(MESSAGE_ID id, void* param) {     if(id == FOO) {         int real_param = (int)param;         // ...     } }   Of course, on a 64 bit machine, I get the error:  error: cast from 'void*' to 'int' loses precision   I would like to correct this so that it still works on a 32 bit machine and as cleanly as possible. Any idea ?
73828
I'm creating a set of enum values, but I need each enum value to be 64 bits wide. If I recall correctly, an enum is generally the same size as an int; but I thought I read somewhere that (at least in GCC) the compiler can make the enum any width they need to be to hold their values. So, is it possible to have an enum that is 64 bits wide?
1982
The following code is generating a stack overflow error for me  int main(int argc, char* argv[]) {     int sieve[2000000];     return 0; }   How do I get around this? I am using Turbo C++ but would like to keep my code in C  EDIT:  Thanks for the advice.  The code above was only for example, I actually declare the array in a function and not in sub main.  Also, I needed the array to be initialized to zeros, so when I googled malloc, I discovered that calloc was perfect for my purposes.  Malloc/calloc also has the advantage over allocating on the stack of allowing me to declare the size using a variable.
93044
What is better: void foo() or void foo(void)? With void it looks ugly and inconsistent, but I've been told that it is good. Is this true?  Edit: I know some old compilers do weird things, but if I'm using just GCC, is void foo() Ok? Will foo(bar); then be accepted?
30179
In C the following horror is valid:  myFunc() {   return 42;  // return type defaults to int. }   But, what about in C++? I can't find a reference to it either way...  My compiler (Codegear C++Builder 2007) currently accepts it without warning, but I've had comments that this is an error in C++.
32717
This question may sound fairly elementary, but this is a debate I had with another developer I work with.  I was taking care to stack allocate things where I could, instead of heap allocating them. He was talking to me and watching over my shoulder and commented that it wasn't necessary because they are the same performance wise.  I was always under the impression that growing the stack was constant time, and heap allocation's performance depended on the current complexity of the heap for both allocation (finding a hole of the proper size) and de-allocating (collapsing holes to reduce fragmentation, as many standard library implementations take time to do this during deletes if I am not mistaken).  This strikes me as something that would probably be very compiler dependent. For this project in particular I am using a  compiler for the  architecture. Insight on this combination would be most helpful, but in general, for GCC, and MSVC++, what is the case? Is heap allocation not as high performing as stack allocation? Is there no difference? Or are the differences so minute it becomes pointless micro-optimization.
55243
In C#, int and Int32 are the same thing, but I've read a number of times that int is preferred over Int32 with no reason given. Is there a reason, and should I care?
26836
Not to long ago, someone told me that long are not 64 bits on 64 bit machines and I should always use int. This did not make sense to me. I have seen docs (such as the one on Apple's official site) say that long are indeed 64 bits when compiling for a 64-bit CPU. I looked up what it was on 64-bit Windows and found         Windows: long and int remain 32-bit in length, and special new data types   are defined for 64-bit integers.      (from )  What should I use? Should I define something like uw, sw ((un)signed width) as a long if not on Windows, and otherwise do a check on the target CPU bitsize?
5968
Programming language books explain that value types are created on the stack, and reference types are created on the heap, without explaining what these two things are. I haven't read a clear explanation of this.  I understand what a stack is. But,    Where and what are they (physically in a real computer's memory)? To what extent are they controlled by the OS or language run-time? What is their scope? What determines the size of each of them? What makes one faster?
93954
I had an article, but I lost it.  It showed and described a couple of C/C++ tricks that people should be careful. One of them interested me but now that I am trying to replicate it I'm not being able to put it to compile.  The concept was that it is possible to change by accident the value of a const in C/C++  It was something like this:  const int a = 3;          // I promise I won't change a const int *ptr_to_a = &amp;a; // I still promise I won't change a int *ptr; ptr = ptr_to_a;  (*ptr) = 5;               // I'm a liar; a is now 5   I wanted to show this to a friend but now I'm missing a step.  Does anyone know what's missing for it to start compiling and working?  ATM I'm getting invalid conversion from 'const int*' to 'int*' but when I read the article I tried and it worked great.
20733
Why does the following code in C work?  const char* str = NULL; str = "test"; str = "test2";   Since str is a pointer to a constant character, why are we allowed to assign it different string literals?  Further, how can we protect str from being modified?  It seems like this could be a problem if, for example, we later assigned str to a longer string which ended up writing over another portion of memory.  I should add that in my test, I printed out the memory address of str before and after each of my assignments and it never changed.  So, although str is a pointer to a const char, the memory is actually being modified.  I wondered if perhaps this is a legacy issue with C?
75269
As per c99 standard, size of long long should be minimum 64 bits. How is this implemented in a 32 bit machine (eg. addition or multiplication of 2 long longs). Also, What is the equivalent of long long in C++.
96976
Is there a way to have a 64 bit enum in C++?  Whilst refactoring some code I came across bunch of #defines which would be better as an enum, but being greater than 32 bit causes the compiler to error.  For some reason I thought the following might work:  enum MY_ENUM : unsigned __int64   {       LARGE_VALUE = 0x1000000000000000,   };
25004
Correct me if I am wrong,  int is 4 bytes, with a range of values from -2,147,483,648 to 2,147,483,647 (2^31) long is 4 bytes, with a range of values from -2,147,483,648 to 2,147,483,647 (2^31)  What is the difference in C++?  Can they be used interchangeably?