From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fc89c,6cb77998e643153b,start X-Google-Attributes: gidfc89c,public X-Google-Thread: 1164f8,6cb77998e643153b,start X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1993-07-10 16:01:40 PST Xref: gmd.de comp.sys.dec:8645 comp.unix.programmer:7427 Path: gmd.de!newsserver.jvnc.net!howland.reston.ans.net!gatech!news-feed-1.peachnet.edu!concert!samba.oit.unc.edu!gibbs.oit.unc.edu!tsnee From: tsnee@gibbs.oit.unc.edu (Tom Snee) Newsgroups: comp.sys.dec,comp.unix.programmer Subject: Pointer alignment/unaligned data access problem with [g]dbm Date: 10 Jul 1993 22:59:53 GMT Organization: University of North Carolina, Chapel Hill Distribution: world Message-ID: <21nhl9$8mp@samba.oit.unc.edu> NNTP-Posting-Host: gibbs.oit.unc.edu Summary: Can someone tell me why I have pointer alignment problems? Keywords: gdbm, dbm, pointer alignment problem, unaligned data access When I use gdbm or dbm on a DECstation running Ultrix (the only platform I have tried), I have some strange problems. The dbm and gdbm database routines return a structure called datum, defined as typedef struct { char *dptr; /* points to data to be stored/fetched */ int dsize; /* size of data */ } datum; To store a structure in the database, I use something like struct mystructure rec, *recptr; datum key, content; key.dptr = keystr; key.dsize = strlen(keystr); content.dptr = &rec; content.dsize = sizeof(struct mystructure); store(key, content); To get the structure back, content = fetch(key); recptr = (struct mystructure *) content.dptr; On this last line, lint says "Possible pointer alignment problem." Compiling and running the code always works, although sometimes I get the runtime warning "Fixed up unaligned data access for pid XXXX (procname) at pc 0x400a18." dbx informs me that this location is a printf statement, where I try to print out fields of the structure I got back from dbm. I don't get these errors if "mystructure" contains only char arrays, but I do if the structure has chars and ints. What is going on? Thanks. Tom Snee