sizeof problem under Slackware 3.5.0 (2.0.34)

sizeof problem under Slackware 3.5.0 (2.0.34)

Post by Tuan Q Hoa » Mon, 31 Aug 1998 04:00:00



Hi,

I have to read messages with a header that looks like
the following:

typedef struct {
  unsigned char packet_type;
  unsigned short length : 16;

Quote:} myhdr;

The problem is that when I do a sizeof(hdr) it returns 4 instead of 3.
This used to work with the gcc 2.7.2.1 but with the new compiler
used under Slackware and Redhat it doesn't.  I think its something like
egcs or another.

Are there any new compiler options that allow my structs to have a byte
padding of 1 byte instead of the largest field type, i.e. 2 bytes?

Thanks,
Tuan

--
--
Tuan Hoang
The MITRE Corporation

 
 
 

sizeof problem under Slackware 3.5.0 (2.0.34)

Post by Rob Kom » Tue, 01 Sep 1998 04:00:00



: Hi,
:
: I have to read messages with a header that looks like
: the following:
:
: typedef struct {
:   unsigned char packet_type;
:   unsigned short length : 16;
: } myhdr;
:
: The problem is that when I do a sizeof(hdr) it returns 4 instead of 3.
: This used to work with the gcc 2.7.2.1 but with the new compiler
: used under Slackware and Redhat it doesn't.  I think its something like
: egcs or another.
:
: Are there any new compiler options that allow my structs to have a byte
: padding of 1 byte instead of the largest field type, i.e. 2 bytes?

how about using `-fpack-struct'?  You might have to isolate the struct
into a few routines if there are other structs around where you want
them to be padded.

Cheers,
Robert Komar            Physics Dept., Univ. of British Columbia, Canada
                        (stationed at the Sudbury Neutrino Observatory)
My mail address can be got from the following Unix command:


 
 
 

sizeof problem under Slackware 3.5.0 (2.0.34)

Post by Erwin S. Andreas » Tue, 01 Sep 1998 04:00:00




>: I have to read messages with a header that looks like
>: the following:
>:
>: typedef struct {
>:   unsigned char packet_type;
>:   unsigned short length : 16;
>: } myhdr;
>:
>: The problem is that when I do a sizeof(hdr) it returns 4 instead of 3.
>how about using `-fpack-struct'?  You might have to isolate the struct
>into a few routines if there are other structs around where you want
>them to be padded.

There's also an __attribute__((packed)) which does it for a single
member of a struct or a variable - i.e. you'd put it after the "length"
and it would force length to have no padding.

Check out "info gcc" which is where all such gcc-extensions are
described - "info gcc" then "s" and "packed" should find the right
section.

In older gccs, you'd then have to, AFAIR, use this
__attribute__((packed)) on each member of the structure that you didn't
want aligned properly - newer gccs (at least egcs, probably gcc 2.8.x
too) allow you to put the __atribute__ after a type, so that all the
members of the structure are packed.

As far as I remember, gcc will then generate correct but slower code
that does not cause alignment faults for such structures, for systems
that require e.g. ints to be aligned on a 4-byte boundary.

--
==============================================================================

<URL:http://www.abandoned.org/drylock/>     <*>         (not speaking for) DDE
==============================================================================

 
 
 

sizeof problem under Slackware 3.5.0 (2.0.34)

Post by Kalle Niemital » Tue, 01 Sep 1998 04:00:00




> : Hi,
> :
> : I have to read messages with a header that looks like
> : the following:
...
> how about using `-fpack-struct'?  You might have to isolate the struct
> into a few routines if there are other structs around where you want
> them to be padded.

Or, try this:

typedef struct {
  unsigned char packet_type;
  unsigned short length /* NOTE: not a bitfield */;

Quote:} __attribute__((aligned(1), packed)) myhdr;

Tested with GCC 2.7.2.1 on sparc-sun-solaris2.5.1.

Unfortunately, this doesn't work if you make length a bitfield or
append __attribute__((mode(HI))) to its definition.

Moving the __attribute__ after myhdr apparently causes the compiler to
ignore it with no warning -- scary!

--

666 MHz getting closer

 
 
 

1. Problem with lp module in slackware 2.0.34

Hi there
I am using slackware, kernel 2.0.34. The problem I am ahving is that I
can't print.  lpr is there, but when I send something to the printer
nothing happens. lpq returns something like :
waiting for lp to become ready (offline ?)
Rank   Owner      Job  Files                                 Total Size
1st    lmontes    1    child.cpp                             1462 bytes

Since I just recently bougth my printer, I did not pay too much
attention to the message "can't find module lp" during boot, but of
course now I do. Sure enough, no lp.o in /lib/modules. So I go and run
"make modules" and "make modules_install". Still nothing. Maybe I didn't
configure lp to be a module, so I go and do make config. The only choice
that seems related is the one about parallel printer support, so I do
choose that to be a module, make it, but still nothing. Decided to
recompile the whole kernel, and then make the modules. Nothing still.
Dedided to look up in the source code for lp.c, compile it an put it
manually in the /lib/modules/2.0.35/misc directory. Now it of course
findt it, but complains about not having version number, so I use insmod
-f, but get a different error that seems to be related to lp.o not being
a module.
So I guess now is time to ask for help. Do anybody have a suggestion?
Why lp doesn't get made when I do make modules? Am I missing something?
Thanks

2. IDE & SCSI Controller lockup.

3. coding style advice for sizeof (long) < sizeof (size_t)?

4. SMC ethernet cards on PCI

5. iBCS modules for RedHat 2.0.34 and Slackware 2.0.29

6. MIME problem w/Apache

7. Slackware and 2.0.34 kernel compile errors

8. PAT(NAT?) with a single IP?

9. ultrastor 34 scsi and slackware 1.1.2?

10. please help: newly compiled kernel cannot compile (2.0.34 slackware)

11. remote timeouts with slackware kernel 2.0.34

12. Workman/Kernel 2.0.34/Slackware

13. ps/2 mouse device not detected slackware/kernal 2.0.34/amd k6/mb:p55-bt