I've a problem with array[global] values getting lost in function call.
Here is the flow.
===========driv er.c=========== ======
/* this is just a driver to test a library wrapper
* originally it's a cobol program calling a c library function
*/
# include "il_entry.h " /* # define s SCANFUN as il_lib_entry */
int
main(void)
{
int SLEN = 8192;
char SIGNAT[SLEN];
char ISTAT[2]={'0', '0'};
char FNAME[32] = {'0'};
SCANFUN(ILREADI MAGE, FNAME, SIGNAT, "8192", ISTAT);
return 0;
}
=============== il_lib_entry.c =============== =============== ===
# include <stdarg.h>
# include <stdlib.h>
# define NARGS 10 /* keeps track of memory allocated
*/
char **calargv;
int calargc;
void il_cob(void);
void
il_lib_entry(ch ar *foo, ...)
{
int i=0, n=0;
va_list argv;
char *v;
if (foo != NULL)
{
n = NARGS;
/* start with 10 ptrs first */
if ((calargv = malloc (NARGS * sizeof(char*))) == NULL)
{
perror("malloc" );
exit(EXIT_FAILU RE);
}
va_start(argv, *foo);
printf("%s\n", foo);
if((calargv[0] = malloc (strlen(foo)+1) ) == NULL)
{
perror("malloc" );
exit(EXIT_FAILU RE);
}
strcpy(calargv[0], foo);
for (i=1; (v=va_arg(argv, char*)) != NULL; i++)
{
/* if (i n)
{
n += NARGS;
calargv = realloc(calargv , n * sizeof(char*));
}
*/
if((calargv[i] = malloc(strlen(v )+1)) == NULL)
{
perror("malloc" );
exit(EXIT_FAILU RE);
}
strcpy(calargv[i], v);
}
/* if (i n)
{
n++;
calargv = realloc(calargv , n * sizeof(char*));
}
*/
calargv[i] = NULL; /* terminate the
array */
va_end(argv);
calargc = i;
il_cobol(); /* join the old route */
for (i=0; calargv[i]; i++)
free(calargv[i]);
free(calargv);
}
}
=============== ===== library code =============== ==
#include <stdio.h>
#include <fcntl.h>
#include "il_lib.h"
#include "il_cob_lib .h"
extern char *calargv[] ;
extern int calargc ;
static int iretval;
#define NFUN sizeof(il_cob_c all)/sizeof(int *)
il_cobol()
{
if (calargc 0) {
int ifun = atoi(calargv[0]);
iretval = 0;
if(ifun < NFUN)
(*il_cob_call[ifun])();
}
return;
}
<snip>
=============== ====== code end =============== =========
When control enters the library code, the contents of calargv[] are
already corrupt. (Though calargc is correct). Appears that values of
calargv[0] to [4] are changing somewhere after il_lib_entry calls
il_cobol. Can't understand why.
Should calargv be declared as const in il_lib_entry? but I'm confused
as to what should be const in the declaration.
il_lib_entry is the wrapper to the library which alredy existing, so
any change in library code is ruled out, but il_lib_entry() can be
changed to suit.
help appreciated.
~yogesh 2 1351
yogeshmk wrote On 08/01/06 11:14,:
I've a problem with array[global] values getting lost in function call.
Here is the flow.
One of the problems (there are probably several, but
it's hard to be sure lacking so much of the actual code)
arises from this mismatch:
=============== il_lib_entry.c =============== =============== ===
[...]
char **calargv;
=============== ===== library code =============== ==
[...]
extern char *calargv[] ;
A pointer-to-something ("something" is a char* in this
case) is not the same type as an array-of-something, so the
same object is being described in two conflicting ways. See
Question 6.1 in the comp.lang.c Frequently Asked Questions
(FAQ) list http://www.c-faq.com/
-- Er*********@sun .com
yogeshmk schrieb:
When control enters the library code, the contents of calargv[]
are already corrupt. (Though calargc is correct). Appears that
values of calargv[0] to [4] are changing somewhere after
il_lib_entry calls il_cobol. Can't understand why.
Are you sure they were populated correctly to begin with?
The code as posted doesn't do anything to verify this.
void
il_lib_entry(ch ar *foo, ...)
[snip]
va_start(argv, *foo);
I don't know what dereferencing will do in this context, but
it's almost certainly something bad. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Newsgroup - Ann |
last post by:
Hi gurus,
I have two files compiled together. One file has the following global
definition:
char s = "asdf";
Another file has the following declaration:
extern char *s;
|
by: exits funnel |
last post by:
Hello,
I have the following three files
//BEGIN test.h
class foo
{
public:
void print( );
private:
|
by: Sona |
last post by:
I understand the problem I'm having but am not sure how to fix it. My
code passes two char* to a function which reads in some strings from a
file and copies the contents into the two char*s. Now when my function
returns, the values stored in the char* are some garbage values (perhaps
because I didn't allocate any memory for them).. but even if I allocate
memory in the function, on the return of this function I see garbage..
here is my...
|
by: Martin Jørgensen |
last post by:
Hi,
Problem:
========
Some of my output functions are beginning to take pretty many
arguments... I mean.... We're talking about 10-15 arguments :-)
So I thought to myself, perhaps this is beginning to get out of hands if
I continue to put in extra functionality in the (file-writing)
output-functions....
|
by: ruffiano |
last post by:
I have a file called first.cpp that contains the following
declarations:
static const char *MY_STRING1 = "My first string";
static const char *MY_STRING2 = "My second string"
If I wanted to use MY_STRING1 and MY_STRING2 in a header file, would
the following be correct?
extern static const char *MY_STRING1;
extern static const char *MY_STRING2;
| |
by: coder |
last post by:
While reading the page on "Reading C Declarations"
<http://www.ericgiguere.com/articles/reading-c-declarations.html>
(recommended by Mr. Heathfield at
<http://www.cpax.org.uk/prg/portable/c/resources.php>), I came across
the following declaration:
extern char *const (*goop( char *b ))( int, long );
which is explained as:
|
by: Bharath |
last post by:
Hi All,
I am a newbie to C++ and I'm trying to figure this out. Can you please
help?
We have 3rd party library that's written in c++. We don't have the
source for it. ldd on that shared library indicates that it depends on
libstdc++. It has a printf() like function called
void xxx_print (char *format, ...)
|
by: dtschoepe |
last post by:
Hi,
I have a homework project I am working on, so be forwarned, I'm new to
C programming. But anyway, having some trouble with a memory
allocation issue related to a char * that is a variable inside of a
structure. I keep getting segmentation fault errors and I am having
trouble understanding why. Here's the parts of the code in question...
This is part of the .h file where the struct us defined...
|
by: Christian Meier |
last post by:
Hello NG
I have the following code:
file1.h:
static const int iValue = 5;
<EOF>
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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();...
|
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...
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |