10-13-2005
My guess is that sizeof cannot work out the size of the struture and is passing back 0, representing a null or undetermined value or an error condition.
What does your documentation for sizeof say about error conditions/values from this function?
6 More Discussions You Might Find Interesting
1. Programming
Hi All,
is it possible to find out the size of an array of structures ( without using 'sizeof' operator). The condition is we have the array of structure instant but we are not aware of the elements inside the structure.
Can someone help me out?
Thanks in advance. (18 Replies)
Discussion started by: rvan
18 Replies
2. Programming
The below code throws the error, since the size of x = 19 is not passed to the cstrCopy function.
using namespace std;
static void cstrCopy(char *x, const char*y);
int main ()
{
char x;
const string y = "UNIX FORUM";
cstrCopy(x,y.c_str());
return 0;
}
void cstrCopy(char *x,... (3 Replies)
Discussion started by: SamRoj
3 Replies
3. Programming
Hi,
There are some bewildering sizeof() questions I have in my mind. Could anyone shed some light on this?
int main() {
printf("%d\n", sizeof(main)); // Ans: 1
}
That is, the sizeof() a function identifier though it is treated internally as a pointer gives 1 byte always, why?
... (5 Replies)
Discussion started by: royalibrahim
5 Replies
4. Programming
Hi,
I have defined the class and call the sizeof(object to class) to get the size.
# include <iostream>
# include <iomanip>
using namespace std;
class sample
{
private:
int i;
float j;
char k;
public:
sample()
{
} (2 Replies)
Discussion started by: ramkrix
2 Replies
5. Shell Programming and Scripting
Hai
how to find size of a file??
ex : /home/kiran/pdk/sample/calibre this is a path
In that I have to find size of a files in side a calibre(it is the folder) like .results or .summary (1 Reply)
Discussion started by: kiran425
1 Replies
6. Programming
Ignoring other considerations for a moment and in general ...
Would there be a difference in result (dot oh or execution) of:
A.
strncpy( a, b, sizeof(a) );
vs.
B.
c = sizeof(a);
strncpy( a, b, c );
My general understanding is (at least I think my understanding is) that... (10 Replies)
Discussion started by: GSalisbury
10 Replies
LEARN ABOUT CENTOS
offsetof
OFFSETOF(3) Linux Programmer's Manual OFFSETOF(3)
NAME
offsetof - offset of a structure member
SYNOPSIS
#include <stddef.h>
size_t offsetof(type, member);
DESCRIPTION
The macro offsetof() returns the offset of the field member from the start of the structure type.
This macro is useful because the sizes of the fields that compose a structure can vary across implementations, and compilers may insert
different numbers of padding bytes between fields. Consequently, an element's offset is not necessarily given by the sum of the sizes of
the previous elements.
A compiler error will result if member is not aligned to a byte boundary (i.e., it is a bit field).
RETURN VALUE
offsetof() returns the offset of the given member within the given type, in units of bytes.
CONFORMING TO
C89, C99, POSIX.1-2001.
EXAMPLE
On a Linux/i386 system, when compiled using the default gcc(1) options, the program below produces the following output:
$ ./a.out
offsets: i=0; c=4; d=8 a=16
sizeof(struct s)=16
Program source
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
int
main(void)
{
struct s {
int i;
char c;
double d;
char a[];
};
/* Output is compiler dependent */
printf("offsets: i=%ld; c=%ld; d=%ld a=%ld
",
(long) offsetof(struct s, i),
(long) offsetof(struct s, c),
(long) offsetof(struct s, d),
(long) offsetof(struct s, a));
printf("sizeof(struct s)=%ld
", (long) sizeof(struct s));
exit(EXIT_SUCCESS);
}
COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
GNU
2008-07-12 OFFSETOF(3)