10-12-2005
but i am getting the result as zero
my program is like this
struct foo
{
char c[];
};
void main()
{
struct foo s;
cout<<sizeof(s);
}
when i compile this and run on solaris 5.8 it gives the output as 0
i dont know why
there is no error in my compilation
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 XFREE86
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
POSIX.1-2001, POSIX.1-2008, C89, C99.
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=%zd; c=%zd; d=%zd a=%zd
",
offsetof(struct s, i), offsetof(struct s, c),
offsetof(struct s, d), offsetof(struct s, a));
printf("sizeof(struct s)=%zd
", sizeof(struct s));
exit(EXIT_SUCCESS);
}
COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
GNU
2017-09-15 OFFSETOF(3)