2

I'm working to polish some existing C code in order to port it to a new compiler (embedded software, we're switching hardware). So I'm trying to scrub the current code with lint, and I'm stumped by an assignment that lint has decided is a strong-typing violation.

The error I'm getting:

--- Module:   GenericFileName.c 
GenericFileName.c  ...  Warning 632: Assignment to strong type
(SubStructureType_T) in context: assignment

The lines of code to which it refers (names changed for readability):

void foo(void)
{
    extern const StructureType_T parent;    
    const SubStructureType_T *localChild;

    localChild = parent.child;   //<-- lint complains about this assignment
    ...
}

The relevant parts of StructureType_T:

typedef struct
{   
    const struct SubStructureType_T *child;
    ...
}StructureType_T;

And finally, the lint option to enable strong-type checking:

-strong(AcXJcb)

Any insight would be greatly appreciated. I've searched around for help on this but haven't found much. I guess lint is a pretty old tool. Thanks for reading!

Scott S.
  • 23
  • 4
  • Where and how is `parent` actually (globally)defined which you have asked external linkage for ? – Mahesh Aug 16 '11 at 15:36
  • Oops, very good question. I should have included that. It looks like this: 'const StructureType_T parent = { 0,0,0,...,0}'. It lives in another module. – Scott S. Aug 16 '11 at 15:39
  • `const StructureType_T parent = { 0,0,0,...,0};` – Scott S. Aug 16 '11 at 15:44
  • This is not really helpful. Since you said it is a old tool, try setting to **NULL** instead of **0** in the initializer list for the pointer. – Mahesh Aug 16 '11 at 15:49
  • Is this relevant? I've got the definition after a `#pragma tsection .parent` statement. Due to the vital nature of the application, we use this type of thing to be very deliberate about where some addresses are stored. – Scott S. Aug 16 '11 at 15:51
  • Tried setting it to **NULL** in the instantiation, unfortunately I am still getting the warning from lint. – Scott S. Aug 16 '11 at 15:56

1 Answers1

1

Is it const SubStructureType_T, as in foo, or const struct SubStructureType_T as in the typedef? Note that the keyword "struct" only appears in the 2nd definition.

Are they the same?

pmg
  • 106,608
  • 13
  • 126
  • 198
  • Oh, of course. I need to have `struct` in the declaration for `*localChild`. I feel silly now. Thanks! – Scott S. Aug 16 '11 at 16:16
  • +1, I bet that's it. See the question [Difference between `struct` and `typedef struct`](http://stackoverflow.com/questions/612328/difference-between-struct-and-typedef-struct-in-c) for details. – Adam Rosenfield Aug 16 '11 at 16:20
  • @Adam @pmg Absolutely. Because I need to use forward declaration, the SubStructureType_T is defined like so: `typedef struct SubStructure_T{ ... } SubStructure_T;`. I'm not sure any compiler would have mistakenly tried to make `localChild` something strange without the `struct`, but this fix makes lint happy. Thanks again. – Scott S. Aug 16 '11 at 16:55
  • What's the harm of keeping `typedef` away from the code and type an extra `struct` everytime it's needed? Don't answer: rhetoric question :) – pmg Aug 16 '11 at 18:07