This is a follow up on a private mail exchange about C++ and C user space
programs seeing diferent things in the same mbuff shared area.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARRRRGGGGHHHHH !!!!

I was telling about it in Vienna. You have used high optimization -O6 and gcc
and g++ have aligned your structures differently. Thus the difference in
sizeof and layout of your structures. No wonder each program sees the same
raw data, but understands it differently.

typedef struct {
  bool inuse;                   /* only used inside shm */
/* g++ - no space, gcc - bool is 4 bytes! */B
  bool valid;
/*  here g++ 2 bytes padding, gcc - bool is 4 bytes! */
  /* the LUT itself with Distance [um] */
  double um[NI_PCI_MIO_XE10_RES+1];

} shm_slut_t;



reading directly slut from shm (each 4096 Bytes)
Debug: Reading from Shared Memory Region <SensorLUT>
        0       0.0000 off:4
        4095    4095.0000 off:32764
inuse: 0 valid:1


crds:/home/motyl/mbuff/petzold/mbuff_test3# ./test_shm -r
Shared Memory for Sensor LUT at 0x400f7000
reading directly slut from shm (each 4096 Bytes)
        0       0.0000 off:8
        4095    0.0000 off:32768
sizeof(bool) == 4
inuse: 0 valid:4

Even using

typedef struct {
..........
} __attribute__((packed)) shm_slut_t;

does not save the problem, because sizeof(bool)==4 in gcc and 1 in g++.

I would like to use this opportunity to stress once again the importance to
use the same compiler flags, volatile, and __attribute__((packed)) to get
right any shared structures.

This can be used to check the position of the fields, I will add it to the
next version of mbuff.

#define FIELD_OFFSET(strptr,field) ((char*)&((strptr)->field)-(char*)strptr)

Such problems are very difficult to find, and I have seen some bugs of type
"works for me but not for you" traced to different layout of kernel's and
module's structures.

I have no idea what has caused your problems with memcpy. Please mail me
again if this problem was caused by something else.

Small remark: you are probably doing too much copying. Shared memory is
designed to avoid it. 

Best regards,
--
Tomasz Motylewski

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to