473,770 Members | 4,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to avoid including C files in other C files in an old code base

Hi All,

We have an old code base which (unfortunatelty ) has some C files that
include other C files:e.g

File.c
=====
#include<stdio. h>
..
void someFunc(){
..
..
}

#include<culpri t.c>

void someOtherFunc() {

callAFunctionDe finedinCluprit( )

}
=====
Here, File.c includesa C file called culprit.c.

Problem:
We are porting this code base to Mainframes. The debugger there
( iSeries system debugger) does not support inclusion of the files.
When control of the execution reaches in culprit.c, debugger is unable
to highlight the statement being executed currently.

Possible Solution;
We could copy-paste the culprit.c in the File.c, However there are
some other files like Second.c that also include culprit.c. So the
code of culprit will be redundant.
Please help, if any other solution exists.

I understand this group is not about debugger/ Mainframes, However I
posted this query in this group because after all this is a bad
programming design as per the C language.

Also, If any one can suggest some place/group that discuss Mainframes.

Thanks and Regards,
Raman Chalotra
Jun 27 '08 #1
5 1600
Raman <ra***********@ gmail.comwrites :
We have an old code base which (unfortunatelty ) has some C files that
include other C files:e.g

File.c
=====
#include<stdio. h>
.
void someFunc(){
}

#include<culpri t.c>

void someOtherFunc() {
callAFunctionDe finedinCluprit( )
}
=====
Here, File.c includesa C file called culprit.c.

Problem:
We are porting this code base to Mainframes. The debugger there
( iSeries system debugger) does not support inclusion of the files.
<snip>
Possible Solution;
We could copy-paste the culprit.c in the File.c, However there are
some other files like Second.c that also include culprit.c. So the
code of culprit will be redundant.

Please help, if any other solution exists.
Can you see any reason why the code is organised this way? If the
original authors are not playing tricks, it should be relatively easy
to replace this mechanism with the normal .h file with declarations
and .c with definitions, combined at like time.

This won't work if tricks are being played. The most common sort of
"trick" is to arrange for the included .c file to generate slightly
different code each time. So you see things like:

....
#define MAX_SIZE 1000
typedef double element_type;
#include "quick-and-dity-array-code.c"
....

where the .c file uses the defined and typedef'd names differently on
each include. If that is what is happening, ask again but giving
details of what is variable between includes -- there may be cleaner
way to do it.

--
Ben.
Jun 27 '08 #2
Ben Bacarisse <be********@bsb .me.ukwrote:
Raman <ra***********@ gmail.comwrites :
We have an old code base which (unfortunatelty ) has some C files that
include other C files:e.g

File.c
=====
#include<stdio. h>
.
void someFunc(){
}

#include<culpri t.c>

void someOtherFunc() {
callAFunctionDe finedinCluprit( )
}
=====
Here, File.c includesa C file called culprit.c.

Problem:
We are porting this code base to Mainframes. The debugger there
( iSeries system debugger) does not support inclusion of the files.
<snip>
Possible Solution;
We could copy-paste the culprit.c in the File.c, However there are
some other files like Second.c that also include culprit.c. So the
code of culprit will be redundant.

Please help, if any other solution exists.
Can you see any reason why the code is organised this way? If the
original authors are not playing tricks, it should be relatively easy
to replace this mechanism with the normal .h file with declarations
and .c with definitions, combined at like time.
This won't work if tricks are being played. The most common sort of
"trick" is to arrange for the included .c file to generate slightly
different code each time. So you see things like:
...
#define MAX_SIZE 1000
typedef double element_type;
#include "quick-and-dity-array-code.c"
...
where the .c file uses the defined and typedef'd names differently on
each include. If that is what is happening, ask again but giving
details of what is variable between includes -- there may be cleaner
way to do it.
Another reason that could fail is if culprit.c defines global
variables with file scope. In this case every place where
culprit.c is included gets its own set of these variables but
when you just call the functions from culprit.c then there
will be only one such set (which also can't be accessed from
the parts that now only call the functions in culprit.c).

Regards, Jens
--
\ Jens Thoms Toerring ___ jt@toerring.de
\______________ ____________ http://toerring.de
Jun 27 '08 #3
On Sat, 07 Jun 2008 02:33:28 -0700, Raman wrote:
Hi All,

We have an old code base which (unfortunatelty ) has some C files that
include other C files:e.g

File.c
=====
#include<stdio. h>
.
void someFunc(){
.
.
}

#include<culpri t.c>

void someOtherFunc() {

callAFunctionDe finedinCluprit( )

}
=====
Here, File.c includesa C file called culprit.c.

Problem:
We are porting this code base to Mainframes. The debugger there (
iSeries system debugger) does not support inclusion of the files. When
control of the execution reaches in culprit.c, debugger is unable to
highlight the statement being executed currently.

Possible Solution;
We could copy-paste the culprit.c in the File.c, However there are some
other files like Second.c that also include culprit.c. So the code of
culprit will be redundant.
Here's a cut-and-paste equivalent that avoids manual
duplication of code. Generate the ".c" sources from
a template using cpp:

1. mv File.c File.tpl
2. Edit File.tpl to add "#ifdef TEMPLATE" around all ".h" includes.
3. Provide for the generation of the source ".c" files in the makefile:
cpp -P -D TEMPLATE File1.tp File.c
Add rules to the makefile to handle .tpl -.c

CPP=gcc -E -P # or /lib/cpp -P, /usr/bin/cpp -P etc.
.SUFFIXES: .tpl
.tpl.c:
$(CPP) -P -DTEMPLATE $^ $@

File.tpl
=====
#ifndef TEMPLATE
#include<stdio. h>
/* Any other includes */
#else
/* This File generated by cpp from File.tpl do not edit. */
#endif
void someFunc(){
..
..
}

#include<culpri t.c>

void someOtherFunc() {

callAFunctionDe finedinCluprit( )

}
=====
>
Please help, if any other solution exists.
Hope that helps. Your cpp may be different.
-Louis
I understand this group is not about debugger/ Mainframes, However I
posted this query in this group because after all this is a bad
programming design as per the C language.

Also, If any one can suggest some place/group that discuss Mainframes.

Thanks and Regards,
Raman Chalotra
Jun 27 '08 #4
Raman <ra***********@ gmail.comwrote:
>
Problem:
We are porting this code base to Mainframes. The debugger there
( iSeries system debugger) does not support inclusion of the files.
When control of the execution reaches in culprit.c, debugger is unable
to highlight the statement being executed currently.
Complain to the vendor. That is a serious and, in my opinion,
unacceptable limitation in the debugger. At the same time, debuggers,
while helpful, are not mandatory. If the code is used in multiple
places as you say, I'd be inclined to leave it be and accept that you'll
need to use alternative techniques to debug it as the lesser of two
evils.

-- Larry Jones

You just can't ever be too careful. -- Calvin
Jun 27 '08 #5
In comp.lang.c, Raman wrote:
Hi All,

We have an old code base which (unfortunatelty ) has some C files that
include other C files
[snip]
We are porting this code base to Mainframes. The debugger there
( iSeries system debugger) does not support inclusion of the files.
When control of the execution reaches in culprit.c, debugger is unable
to highlight the statement being executed currently.
One potential way around your problem is to see if your C compiler supports
an option to save the source code "after preprocessing". With this option,
you could save the source code where all #includes and #defines have been
resolved, and this can then be used as both the source input into your C
compile stage, /and/ the source input into your debugger.

If you were using the GNU C compiler (and in the iSeries, that /may/ be one
of your compiler choices), the -E compiler option "stops after the
preprocessing stage... The output is in the form of preprocessed source
code". Look for some similar option on your C compiler

[snip]
HTH
--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------
Jun 27 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1330
by: Andres Baravalle | last post by:
Hi, I am quite new with python and I'm developing a package that is including a binary file (eggtrayiconmodule.so) that is open source. My software is developed in part under linux, and now I would like to make it fully portable to other unix-like platforms. Therefore I need to provide the source and integrate eggtrayicon compiling in my setup.py. At this point I don't know how go on.
5
5689
by: mayamorning123 | last post by:
A comparison among six VSS remote tools including SourceOffSite , SourceAnyWhere, VSS Connect, SourceXT, VSS Remoting, VSS.NET To view the full article, please visit http://www.BetterVssRemoting.com Better VSS Remote Access Tool This article makes a detailed comparison among SourceAnyWhere 4.0, SourceOffSite 4.1, VSS Connect 1.5, SourceXT 2.1, VSS Remoting 2.5,
1
2462
by: Scott Yost | last post by:
I have a managed class A which I import via a DLL. public __gc class A { public B otherClass; } And another class C which is just in a CPP file - not in the DLL. #include <b.h> class C
9
3228
by: Bob Achgill | last post by:
I would like to use the timestamp on files to manage the currency of support files for my VB windows application. In this case I would only put the timestamp of the file in the management database and not the file itself. To do this I will need to have a File class property for Create time and date that will let me "set" the Create time and date of the file to my own chooseing. The VB file class does not appear to have the ability
3
4309
by: s99999999s2003 | last post by:
hi i wrote some code to compare 2 files. One is the base file, the other file i got from somewhere. I need to compare this file against the base, eg base file abc def ghi eg another file
1
2187
by: relisoft | last post by:
SEATTLE, Washington. - July 12, 2006: Reliable Software® announces the upcoming release of Code Co-op® version 5.0. Code Co-op is an affordable peer-to-peer version control system for distributed development enabling collaboration through Email, LAN, or VPN-no server required. The upcoming release of Code Co-op 5.0 is due out this fall. With this release Reliable Software continues its track record of innovation by introducing...
7
22049
by: amit.atray | last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc) having some Old C-Code (ansi + KR Style) and code inspection shows some big size variable (auto) allocated (on stack) say for ex. char a; (this type of code and other complex mallc/free etc is used frequently and total approx 450 files, each file is of approx/avg 1000 line,
7
6605
by: Pietro Cerutti | last post by:
Hi group, I just noticed that a malloc w/out relative free occurs in the standard C library (or at least, on my implementation of it). #include <stdio.h> int main(void) { printf("%s\n", "Hello"); return (0); }
34
3690
by: =?ISO-8859-1?Q?Marcel_M=FCller?= | last post by:
Hi, is there a way to avoid the automatic copy constructor generation. I do not want the object to be non-copyable. I simply do not want that copying is done by the default copy constructor. But there is a constructor that accepts the base class. This one should be used for copying. In fact i have a set of classes with a common abstract base. The implementations do not have own data members. They only implement
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9439
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.