[Click] wifi llc handling problem in Click 1.5

Steven Augart saugart at mazunetworks.com
Thu Sep 21 09:18:54 EDT 2006


On Thu, 2006-09-21 at 11:32 +0200, Mathias Kurth wrote:
> Hi Eddie,
> 
> Maybe there is something wrong with my compiler but it reports a size of 4
> for the llc header definition.
> Here is a cut&paste example that demonstrates what I mean:
Dear Mathias,

If you run sizeof (char *) on any lvalue, you'll get whatever the size
of a character pointer is on your machine, 4 bytes on most compiler
implementations on a 32-bit machine.

Since almost all of the machines in common use today have the same size
pointers for everything, running sizeof on the definition you use for
wifi_llc_header will give you the sizeof a pointer to const uint8_t on
your machine, which is probably also 4 bytes.


There's all the difference in the world between sizeof "An array of
char" and sizeof (char *) "an array of char"; in the second case, you're
getting the size of a character pointer.

I hope that the example I append will help clarify the situation.

--Steven

The C program:

#include <stdio.h>

struct {
     int a;

     char b;

     
     char *c;
} foo[9999];


int main()
{
     printf( "sizeof (char *) foo: %zu\n", sizeof( (char *) foo));
     printf( "sizeof  foo: %zu\n", sizeof( foo));
}


And its output:

 ./foo
sizeof something: 4
sh-3.1$ ./foo
sizeof (char *) foo: 4
sizeof  foo: 119988
sh-3.1$ 

gcc version 4.1.1 20060525 (Red Hat 4.1.1-1)




More information about the click mailing list