Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Modifing existing header file (http://www.velocityreviews.com/forums/t315774-modifing-existing-header-file.html)

Sujan Datta 10-14-2003 07:55 PM

Modifing existing header file
 
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

Eric Sosman 10-14-2003 08:22 PM

Re: Modifing existing header file
 
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@sun.com

Gordon Burditt 10-14-2003 11:03 PM

Re: Modifing existing header file
 
>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

Sujan Datta 10-15-2003 02:30 PM

Re: Modifing existing header file
 
gordonb.xm6lu@sneaky.lerctr.org (Gordon Burditt) wrote in message news:<bmhvcg$213@library1.airnews.net>...
> >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



All times are GMT. The time now is 07:32 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.