Modifing existing header file

Discussion in 'C Programming' started by Sujan Datta, Oct 14, 2003.

  1. Sujan Datta

    Sujan Datta Guest

    What are the possible effects of modifying an existing header file,
    which includes bunch of defines, function prototypes and some struct
    definitions. The structure of the header file looks something like
    this

    //Start of header
    Define
    Define
    Define
    Define
    ….
    Define
    Function prototype
    Function prototype
    ….
    Define

    Struct abc {
    Int m1
    Int m2
    };
    define
    define
    //End of header

    This header file is shared between multiple C files, which are
    compiled into separate executables. However, these separate
    executables run on the same machine and work in conjunction with each
    other.
    Let say one of the C file is changed along with the header file, where
    some defines and function prototypes were added in the middle of the
    file as opposed to the end of the file. After compiling the
    executable that uses the modified C file, what are the chances that
    the new executable will cause problems when ran with the executables
    compiled with older version of the h file.
    I guess the best way to go is to add them at the end of the h file.
    But I am wondering what kind changes in the middle of h will not cause
    major headaches granted that the members in the struct are not
    changed.
    I realize that this is a very general question but the code is too big
    for posting. Sorry for that. Thanks in advance to anyone who can
    shed some light on this.
    In the case that this is not the right place to post this question,
    can somebody suggest a different group
    -Sujan
     
    Sujan Datta, Oct 14, 2003
    #1
    1. Advertising

  2. Sujan Datta

    Eric Sosman Guest

    Sujan Datta wrote:
    >
    > What are the possible effects of modifying an existing header file,
    > which includes bunch of defines, function prototypes and some struct
    > definitions. The structure of the header file looks something like
    > [...]
    > This header file is shared between multiple C files, which are
    > compiled into separate executables. However, these separate
    > executables run on the same machine and work in conjunction with each
    > other.
    > Let say one of the C file is changed along with the header file, where
    > some defines and function prototypes were added in the middle of the
    > file as opposed to the end of the file. After compiling the
    > executable that uses the modified C file, what are the chances that
    > the new executable will cause problems when ran with the executables
    > compiled with older version of the h file. [...]


    The programs should continue to work correctly with
    each other, provided none of the data types, coded values,
    and so on that they share have been changed. Adding new
    types and declarations won't affect existing programs that
    don't use the new stuff. Therefore, it doesn't matter where
    in the header they are added.

    If the header contains function and/or data definitions
    as opposed to mere declarations (an uncommon practice, but
    it does sometimes make sense), adding new code or new data
    to the header *does* change all programs, new and old, that
    use the header. Also, the position at which the new material
    is added *may* make a difference.

    If you're in the slightest doubt, take no chances:
    recompile everything that uses the changed header.

    --
     
    Eric Sosman, Oct 14, 2003
    #2
    1. Advertising

  3. >This header file is shared between multiple C files, which are
    >compiled into separate executables. However, these separate
    >executables run on the same machine and work in conjunction with each
    >other.


    What does "work in conjunction with each other" mean?
    Does this mean that copies of the struct are saved in disk
    files which are created/used by more than one of these programs?

    >Let say one of the C file is changed along with the header file, where
    >some defines and function prototypes were added in the middle of the
    >file as opposed to the end of the file.


    The ordering of defines and function prototypes usually doesn't
    matter, unless existing code uses the symbol being newly #define'd.

    On the other hand, changing a structure definition of a structure
    which is saved on disk may involve recompiling *ALL* programs
    that use that structure *AND* converting all existing data files
    containing that structure to the new format (including the backups,
    and the archives punched on cards and paper tape).

    >After compiling the
    >executable that uses the modified C file, what are the chances that
    >the new executable will cause problems when ran with the executables
    >compiled with older version of the h file.


    In ANSI C, you run one program at a time. What does "run with" mean?
    One program uses the other's output? In that case, it would depend
    a lot on what the output IS, wouldn't it? If your changes now
    allow the "sex" field to contain "Maybe" in addition to "Male",
    "Female", "Yes", and "No", anything dealing with that field may
    have to deal with the new possible value.

    >I guess the best way to go is to add them at the end of the h file.


    I see no reason why that would help the problem. For example,
    I see no reason why the line:
    #define if else
    wouldn't wreak exactly the same havoc whether you put it at
    the beginning or the end.

    >But I am wondering what kind changes in the middle of h will not cause
    >major headaches granted that the members in the struct are not
    >changed.
    >I realize that this is a very general question but the code is too big
    >for posting. Sorry for that. Thanks in advance to anyone who can
    >shed some light on this.


    You need to be a lot more specific.

    >In the case that this is not the right place to post this question,
    >can somebody suggest a different group


    Gordon L. Burditt
     
    Gordon Burditt, Oct 15, 2003
    #3
  4. Sujan Datta

    Sujan Datta Guest

    (Gordon Burditt) wrote in message news:<bmhvcg$>...
    > >This header file is shared between multiple C files, which are
    > >compiled into separate executables. However, these separate
    > >executables run on the same machine and work in conjunction with each
    > >other.

    >
    > What does "work in conjunction with each other" mean?
    > Does this mean that copies of the struct are saved in disk
    > files which are created/used by more than one of these programs?
    >

    One of the executable is running all the time, some are running as
    daemons in the background (do not know the exact number) and couple of
    the executables are invoked by the daemons directly.(by system() call)
    None of the programs however write anything to a file thats is read
    by another program.

    > >Let say one of the C file is changed along with the header file, where
    > >some defines and function prototypes were added in the middle of the
    > >file as opposed to the end of the file.

    >
    > The ordering of defines and function prototypes usually doesn't
    > matter, unless existing code uses the symbol being newly #define'd.
    >
    > On the other hand, changing a structure definition of a structure
    > which is saved on disk may involve recompiling *ALL* programs
    > that use that structure *AND* converting all existing data files
    > containing that structure to the new format (including the backups,
    > and the archives punched on cards and paper tape).
    >
    > >After compiling the
    > >executable that uses the modified C file, what are the chances that
    > >the new executable will cause problems when ran with the executables
    > >compiled with older version of the h file.

    >
    > In ANSI C, you run one program at a time. What does "run with" mean?
    > One program uses the other's output? In that case, it would depend
    > a lot on what the output IS, wouldn't it? If your changes now
    > allow the "sex" field to contain "Maybe" in addition to "Male",
    > "Female", "Yes", and "No", anything dealing with that field may
    > have to deal with the new possible value.
    >
    > >I guess the best way to go is to add them at the end of the h file.

    >
    > I see no reason why that would help the problem. For example,
    > I see no reason why the line:
    > #define if else
    > wouldn't wreak exactly the same havoc whether you put it at
    > the beginning or the end.
    >
    > >But I am wondering what kind changes in the middle of h will not cause
    > >major headaches granted that the members in the struct are not
    > >changed.
    > >I realize that this is a very general question but the code is too big
    > >for posting. Sorry for that. Thanks in advance to anyone who can
    > >shed some light on this.

    >
    > You need to be a lot more specific.

    The extent of the changes are: Someone changed a C file that only
    effects one of the executables. Also 2 or 3 defines were added in the
    middle of the h file and couple of lines down 2 function prototypes
    were added. Now I compiled all the programs with the new header. But
    on the machine where all the programs are running ... I only replaced
    the program that was effected by a change in the C file. I did not
    replace all the older version of the programs with the newly compiled
    version. So one of the newly compiled executables is running with the
    older executables.
    >
    > >In the case that this is not the right place to post this question,
    > >can somebody suggest a different group

    >
    > Gordon L. Burditt
     
    Sujan Datta, Oct 15, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?VG9t?=

    modifing the request stream of HttpModule

    =?Utf-8?B?VG9t?=, Oct 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    473
    =?Utf-8?B?VG9t?=
    Oct 24, 2005
  2. Dennis M. Marks
    Replies:
    1
    Views:
    410
    Beauregard T. Shagnasty
    Sep 18, 2004
  3. Nitya Prakash

    Modifing resx file at run time in asp.net 1.1

    Nitya Prakash, Mar 8, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    351
    Nitya Prakash
    Mar 8, 2007
  4. zaley
    Replies:
    1
    Views:
    216
    Helmut Jarausch
    Feb 20, 2008
  5. dd007
    Replies:
    19
    Views:
    324
    Bart Lateur
    May 13, 2006
Loading...

Share This Page