Hi, suppose you have the following structure:
#include <windows.h> // BOOL is here.
#include <stdio.h>
typedef struct {
BOOL someBool;
char someCharArray[100];
int someIntValue;
BOOL moreBools, anotherOne, yetAgain;
char someOthercharArray[23];
int otherInt;
} Test;
int main(void) {
printf("Structure size: ...
For example result of this code snippet depends on which machine: the compiler machine or the machine executable file works?
sizeof(short int)
...
Is it possible for the sizeof operator to ever return 0 (zero) in C or C++? If it is possible, is it correct from a standards point of view?
...
How can I find the size of an abstract class?
class A
{
virtual void PureVirtualFunction() = 0;
};
Since this is an abstract class, I can't create objects of this class. How will I be able to find the size of the abstract class A using the 'sizeof' operator?
...
I know that a char and an int are calculated as being 8 bytes on 32 bit architectures due to alignment, but I recently came across a situation where a structure with 3 shorts was reported as being 6 bytes by the sizeof operator. Code is as follows:
#include <iostream>
using namespace std ;
struct IntAndChar
{
int a ;
unsigned c...
How can I change the Default Size of the filterBy text box in Rich Table? In all the columns, it has a same (fix) size.
I used the property width, but it didn't work.
...
So, you know how the primitive of type char has the size of 1 byte? How would I make a primitive with a custom size? So like instead of an in int with the size of 4 bytes I make one with size of lets say 16.
Is there a way to do this? Is there a way around it?
...
Hi,
I want to copy an int array to another int array. They use the same define for length so they'll always be of the same length.
What are the pros/cons of the following two alternatives of the size parameter to memcpy()?
memcpy(dst, src, ARRAY_LENGTH*sizeof(int));
or
memcpy(dst, src, sizeof(dst));
Will the second option always ...
Hello,
gcc 4.4.1 c89
I have the following code snippet:
#include <stdlib.h>
#include <stdio.h>
char *buffer = malloc(10240);
/* Check for memory error */
if(!buffer)
{
fprintf(stderr, "Memory error\n");
return 1;
}
printf("sizeof(buffer) [ %d ]\n", sizeof(buffer));
However, the sizeof(buffer) always prints 4. I know t...
Hi,
is it possible to return the sizeof a derived class already from base class/struct?
imho the size of a class is a kind of property of itself, like the weight of a human being. But I don't want to write the same function in every class.
many thanks in advance
Oops
PS: so code to make my question more clear:
template <typename T>
...
If I write
int main()
{
int a[100] = {1,2,3,4,};
cout<<sizeof(a)/sizeof(a[0])<<endl; //a is a pointer to the first elem of array,
//isn't it
return 0;
}
I get 400!
If I write
void func(int *a);
int main()
{
int a[100] = {1,2,3,4,};
func(a);
return 0;
}
void func(int...
Hello. My task was to create pseudodatabase in c++. There are 3 tables given, that store name(char*), age(int), and sex (bool). Write a program allowing to :
- add new data to the tables
- show all records
- sort tables with criteria :
- name increasing/decreasing
- age increasing/decreasing
- sex
Using function templa...
This is too basic I think, but how do both of these work?
return true; // 1
and
return (true); // 2
Similar: sizeof, exit
My guess:
If return was a function, 1 would be
erroneous.
So, return should be a unary
operator that can also take in
brackets... pretty much like unary
minus: -5 and -(5), both are
okay.
...
On my System:
sizeof(long) in c++ is 4 aka 32bits
sizeof(long) in c# is 8 aka 64 bits
So in my Interop method declarations I've been substituting c++ longs with c# int's however I get the feeling this isn't safe?
Why is a long the same size as an int in c++? And long long is 64bits? What's next a long long long long??
...
I have this situation where an EXE program imports a DLL for a single function call. It works by passing in a custom structure and returning a different custom structure. Up till now it's worked fine until I wanted one of the structs data members to be a vector < MyStruct >
When I do a sizeof(vector< MyStruct >) in my program I get a si...
I just found this code on wikipedia.
Link: http://en.wikipedia.org/wiki/Sizeof#Use
The code:
/* the following code illustrates the use of sizeof
* with variables and expressions (no parentheses needed),
* and with type names (parentheses needed)
*/
char c;
printf("%zu,%zu", sizeof c, sizeof(int));
It states that: "The z prefix ...
I am just starting with cpp and I've been following different examples to learn from them, and I see that buffer size is set in different ways, for example:
char buffer[255];
StringCchPrintf(buffer, sizeof(buffer), TEXT("%s"), X);
VS
char buffer[255];
StringCchPrintf(buffer, 255*sizeof(char), TEXT("%s"), X);
Which one is the correc...
I've noticed that in c/c++ a lot of Win32 API structs need to be told how big they are.
i.e someStruct.pbFormat = sizeof(SomeStruct)
Why is this the case? Is it just for legacy reasons? Also any idea what "pb" stands for too?
EDIT: oops, yeah I meant "cbFormat"
...
What will be equivalent of this in Java?
for (i = (sizeof(num)*8-1); i; i--)
num is given number, not array. I want to reverse bits in integer.
...
Consider the following code:
template<bool> class StaticAssert;
template<> class StaticAssert<true> {};
StaticAssert< (-1 < sizeof(int)) > xyz1; // Compile error
StaticAssert< (-1 > sizeof(int)) > xyz2; // OK
Why is -1 > sizeof(int) true?
Is it true that -1 is promoted to unsigned(-1) and then unsigned(-1) > sizeof(int).
Is it true ...