CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

sizeof not operating correctly on array member of struct

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

sizeof not operating correctly on array member of struct
PostPosted: Mon Oct 11, 2004 3:29 pm     Reply with quote

I have a structure defined as follows:
Code:
struct STRUCT_INFO {
   U32_2xU16_4xU8 sssSize;
   char           GUID[16];
   U16_2xU8       numberOfConfigurations;
   unsigned int8  numberOfAudioChunks;
   unsigned int32 configurationAddresses[MAX_CONFIGURATIONS];
   unsigned int16 numberOfTuples;
};

I also have a function that looks like this:
Code:
void f(struct STRUCT_INFO *structPtr) {
   unsigned int8 sizeVar;

   sizeVar = sizeof(structPtr->GUID);
}

I would expect sizeVar to be set to 16, since the member array is statically allocated. But it gets 2 instead. Am I missing a syntax gotcha?

--
Jeff S.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 11, 2004 3:46 pm     Reply with quote

Can you post a full test program, in which you call the function,
and define all those special data types ?

I did a test program, and it appeared to work OK (from looking
at the .LST file), but unless we see your test program,
we're not really looking at the same problem.
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 11, 2004 3:50 pm     Reply with quote

PCM programmer wrote:
Can you post a full test program, in which you call the function,
and define all those special data types ?

I did a test program, and it appeared to work OK (from looking
at the .LST file), but unless we see your test program,
we're not really looking at the same problem.


I'll have to extract the relevant pieces, 'cause I'm prohibiting from posting it as-is.

--
Jeff S.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 11, 2004 4:03 pm     Reply with quote

I didn't mean post your whole program. I meant just re-post
the parts that were in your original post, plus put in one line
of code to call the function. ie., put in a main().
And if necessary, get rid of the fancy custom data types and
put in a basic type, which is what I suspect they are anyway.

In other words, you don't have to give away any IP, just
make us a test program so that we can compile it and look
at the .LST file.
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 11, 2004 4:13 pm     Reply with quote

PCM programmer wrote:
I didn't mean post your whole program. I meant just re-post
the parts that were in your original post, plus put in one line
of code to call the function. ie., put in a main().
And if necessary, get rid of the fancy custom data types and
put in a basic type, which is what I suspect they are anyway.

In other words, you don't have to give away any IP, just
make us a test program so that we can compile it and look
at the .LST file.


Here's a standalone source file that demonstrates the problem. I'm using PCH v3.212 with a PIC18F452. For all I know my fancy typing may be contributing to the problem, so I've left it in.

Code:
#include "18F452.h"     // Select the target processor
#device *=16


#id checksum            // The ID locations in the PIC will be the firmware checksum
// Fuses are really just suggested settings for the PIC programmer
#fuses  HS,NOWDT,PUT,NOPROTECT,BROWNOUT,NOLVP,NOCPD,NOWRT

#use delay (clock=24000000)   // Instruct the compiler to generate delay routines based on a 24MHz clock (NO WDT REPORTING)

#define SSS_MAX_CONFIGURATIONS         2

struct STRUCT_SSS_INFO {
   char           GUID[16];
   unsigned int8  numberOfConfigurations;
   unsigned int8  numberOfAudioChunks;
   unsigned int32 configurationAddresses[SSS_MAX_CONFIGURATIONS];
   unsigned int16 numberOfEpochTuples;
};

enum SSS_STATUS {SSS_OK, SSS_TIMEOUT, SSS_AUDIO_PIC_NOT_RESPONDING};

SSS_STATUS sss__readSSS(struct STRUCT_SSS_INFO *sssInfoPtr) {
   unsigned int8 sizeVar;
   sizeVar = sizeof(sssInfoPtr->GUID);
}

void main() {
   struct STRUCT_SSS_INFO structVar;
   
   sss__readSSS(&structVar);
}


--
Jeff S.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 11, 2004 4:27 pm     Reply with quote

I don't have PCH in vs. 3.212, so I tested it with PCM.

Results:

PCM 3.212 has the error:
Code:
0000                00307 .....    sizeVar = sizeof(sssInfoPtr->GUID);   
0004 3002       00308 MOVLW  02
0005 00BF       00309 MOVWF  3F

PCM 3.191 has the error:
Code:
0000                00290 .....    sizeVar = sizeof(sssInfoPtr->GUID);   
0004 3002       00291 MOVLW  02
0005 00BF       00292 MOVWF  3F

PCM 3.188 works:
Code:
0000                00290 .....    sizeVar = sizeof(sssInfoPtr->GUID);   
0004 3010       00291 MOVLW  10
0005 00BF       00292 MOVWF  3F


---------------
As a side note, this is why people are always wishing that CCS
would do regression testing to prevent this kind of thing.
http://www.webopedia.com/TERM/R/regression_testing.html
http://c2.com/cgi/wiki?RegressionTesting
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group