From: Josh S. <jo...@4s...> - 2003-07-29 15:22:22
|
Your 'dd' declaration is being created in the code segment. This is because it is a constant. The issue here is that the asm for test.c is created before it knows where dd is stored. Your extern statement does not specify that dd is a constant, so test.asm is created assuming that dd will be in the idata section. If you add a const qualifier on your extern, it should work fine. I didn't try it myself, but the generated code is now correct... Josh Stone > -----Original Message----- > From: sdc...@li... > [mailto:sdc...@li...]On Behalf Of Scott Bronson > Sent: Monday, July 28, 2003 6:20 PM > To: sdc...@li... > Subject: [Sdcc-user] Help chasing a struct bug? > > > I think I've found a bug in SDCC, but because I'm not > real confident of my understanding of pointers and 8051 > memory areas, I'm not sure. > > Here's the deal: If I define a structure in the C file > in which it is used, weverything works perfectly. However, > if I define the structure in another C file > ("extern DeviceDescriptor dd;"), it goes horribly wrong. > I get garbage when I read from the structure (the simulator > always returns 0, and my 8051 dev board returns values from > code memory). > > > Here's how to reproduce this using the attached code. > > 1. Verify that INCLUDE_DD is set to 1 in dd.h > 2. "make sim", and in another window "make net" > 3. Type "go" in the simulator window. Notice how > the serial output is correct: "dd.length: 42" > > 4. Set INCLUDE_DD to 0 in dd.h. This means that > the dd struct will be defined in dd.c rather > than test.c. > 5. "make sim", "make net" > 6. "go". Serial output: "dd.length: 0" > > Can anyone tell me what's going wrong? Thanks, > > - Scott > > |