sizeof

Are there machines, where sizeof(char) != 1 ?

Are there machines (or compilers), where sizeof(char) != 1 ? Does C99 standard says that sizeof(char) on standard compliance implementation MUST be exactly 1? If it does, please, give me section number and citation. Upd: If I have a machine (CPU), which can't address bytes (minimal read is 4 bytes, aligned), but only 4-s of bytes (uint...

In C, why is sizeof(char) 1, when 'a' is an int?

I tried printf("%d, %d\n", sizeof(char), sizeof('a')); and got 1, 4 as output. If size of a character is one, why does 'c' give me 4? I guess it's because it's an integer. So when I do char ch = 'c'; is there an implicit conversion happening, under the hood, from that 4 byte value to a 1 byte value when it's assigned to the char variab...

Allocating space for pointers to struct

In another post link text I am trying to do the same thing with a struct, but I have a problem with my sizeof operator, so in the integer case, I did this: size_t totalMem = rows * sizeof(int *) + rows * cols * sizeof(int)); And in the struct case I did this: size_t totalMem = (rows * sizeof(struct TEST *)) + (rows * cols * sizeof(s...

Using sizeof() on malloc'd memory

Possible Duplicate: newbie questions about malloc and sizeof I am trying to read strings into a program. When I noticed that the strings were sometimes being corrupted, I tried the following code: void *mallocated = malloc(100); printf("sizeof(mallocated) = %d\n", sizeof(mallocated)); According to my program, the size of...

How to determine the size of an array of strings in C++?

I'm trying to simply print out the values contained in an array. I have an array of strings called 'result'. I don't know exactly how big it is because it was automatically generated. From what I've read, you can determine the size of an array by doing this: sizeof(result)/sizeof(result[0]) Is this correct? Because for my program, ...

sizeof(...) = 0 or conditional variable declaration in c++ templates

Suppose I have something like this: struct EmptyClass{}; template<typename T1, typename T2 = EmptyClass, typename T3 = EmptyClass, typename T4 = EmptyClass, ..., typename T20> class PoorMansTuple { T1 t1; T2 t2; ... T20 t20; }; Now, I may waste up to 19bytes per PoorMansTuple. Question is: 1) Is there a way...

Struct size differences between solaris sparc and solaris x86

hi, I am porting our application from solaris sparc to solaris x86 and I encountered a size differences of struct between these two architecture. for example; I have a struct like typedef struct mystructS { double a; double b; double c; double d; double e; double f; double g; double h; double aa; double ab; doubl...

Size of C data types on different machines & sizeof(complex long double)

Hi there, does anybody know a website or a paper where the sizes of C data types were compared on different machines? I'm interested in values of some 'big' machines like a System z or the like. And: Is there an upper bound of bytes that the biggest native datatype on any machine can have and is it always of the type complex long double...

Why is the size of an empty class in C++ not zero?

Why does the following output 1? #include <iostream> class Test { }; int main() { std::cout << sizeof(Test); return 0; } ...

Assigning char value in one array to char value in another array

Sounds easy, but I've got a bug and I'm not sure what's causing it? nopunccount = 0; char *ra = new char[sizeof(npa)]; while (nopunccount <= strlen(npa)) { ra[nopunccount] = npa[strlen(npa) - nopunccount]; nopunccount++; } ra never gets a value into it and I have verified that npa has char values to provide within the nopunc...

sizeof() a vector

Hello! I have a vector<set<char> > data structure (transactions database) and I want to know the size of it. When I use sizeof() with each set<char> the size is 24 in spite of the set contains 3, 4 or 5 chars. Later, when I use sizeof() with the vector<set<char> > the size is 12... I suppose this is not the way to know the size of a data...

size of struct - size_t in c

For some reason I keep getting segmentation fault when I try to get the size of my struct. struct my_struct { char *a; int b; }; int main(int argc, char *argv[]) { struct my_struct dastruct; size_t len = sizeof(dastruct) / sizeof(struct my_struct); // error qsort(dastruct, len, sizeof(struct my_struct), cmp); ... }...

Silverlight 4.0: How to determine the file size of an object in MemoryStream

byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); How will I determine its file size of an image? ...

Size of a class with 'this' pointer

The size of a class with no data members is returned as 1 byte, even though there is an implicit 'this' pointer declared. Shouldn't the size returned be 4 bytes(on a 32 bit machine)? I came across articles which indicated that 'this' pointer is not counted for calculating the size of the object. But I am unable to understand the reason f...

How I return the size of the pointer that I have allocate with malloc?

See this example! int main( int argc, char ** argv ) { int *ptr = malloc(100 * sizeof (int)); printf("sizeof(array) is %d bytes\n", sizeof(ptr)); } The printf function return only 4 bytes! What is wrong? Thanks so much!!! ...

sizeof abuse : get the size of a const table

When declaring a const table, it is possible to get the size of the table using sizeof. However, once you stop using the symbol name, it does not work anymore. is there a way to have the following program output the correct size for table A, instead of 0 ? #include <stdio.h> struct mystruct { int a; short b; }; const struct my...

Questions on usages of sizeof

Question 1 I have a struct like, struct foo { int a; char c; }; When I say sizeof(foo), I am getting 8 on my machine. As per my understanding, 4 bytes for int, 1 byte for char and 3 bytes for padding. Is that correct? Given a struct like the above, how will I find out how many bytes will be added as padding? Question 2 I am...

sizeof continues to return 4 instead of actual size

#include <iostream> using namespace std; int main() { cout << "Do you need to encrypt or decrypt?" << endl; string message; getline(cin, message); int letter2number; for (int place = 1; place < sizeof(message); place++) { letter2number = static_cast<int>(message[place]); cout << letter2number <...

Checking the sizeof an integer type in the preprocessor

Possible Duplicate: Why cant I use sizeof in a preprocessor condition ? How can I check the size of an unsigned in the preprocessor under g++? sizeof is out of the question since it is not defined when during preprocessing. ...

Should I always include stddef.h if I use sizeof and size_t

Hi, if I'm using the sizeof operator and making use of size_t in my code, do I have necessarily have to include stddef.h? I haven't included stddef.h, and my code compiles without warning with both MVS2008 and with Borland C++ BuilderX. Thanks a lot... ...