Same struct, different sizes.

Discussion in 'C Programming' started by Control Freq, Mar 9, 2009.

  1. Control Freq

    Control Freq Guest

    Hi,
    Apologies if you have heard this before, But,
    I have inherited a large project, and I have found a struct defined in
    one header file, and another structure of the same name in another
    header file.

    Now, the two structs are *almost* the same, but one has a char array
    larger than the other.

    It looks like the two structs should be identical, and one header file
    should have been used throughout.
    But, the connection has been lost at some point in history.

    I discovered it when my program crashed when a pointer to the struct
    was used in a function - with the different struct definition. It
    stomped on the return address.

    Anyway, I am concerned that this might be a timebomb in other places
    in the project.

    Is there a way that the compiler (or linker) can warn me that there is
    a structure size problem like this?

    Looking forward to your response.

    Regards
     
    Control Freq, Mar 9, 2009
    #1
    1. Advertisements


  2. You should check your program with the QAC tool.It can check the same
    problems.
    Or you can write a shell program for check your code!
     
    Active Volcano, Mar 9, 2009
    #2
    1. Advertisements

  3. Control Freq

    Ben Pfaff Guest

    If the program is carefully designed, then it may be possible to
    include all the header files into a single .c file. If you do
    this, then the compiler will complain about the duplicate struct
    definition.
     
    Ben Pfaff, Mar 9, 2009
    #3
  4. Control Freq

    Control Freq Guest

    Hi, thanks for in-depth reply.
    But, I know what is happening, and why.
    But, I am concerned that this sort of thing is littered all over the
    project.
    There are hundreds of files in this legacy project.
    I am hoping that the compiler can find the problems for me, without me
    going through every file by hand.
    I simply don't have time for that.


    Regards
     
    Control Freq, Mar 11, 2009
    #4
  5. Control Freq

    JosephKK Guest

    Grep ought to help with that.

    Then put it into a proper revision control system.
    .
     
    JosephKK, Mar 15, 2009
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.