Hi
I have written C code in Unix env.
the c program is as follows:
include<stdio.h>
#include<string.h>
#include<malloc.h>
char * sayhello(char *Arg1)
{
char *s1;
const char *s2="hello";
s1=(char *)malloc(20);
s1="hi";
strcat(s1,s2);
return(s1);
}
I have created a parallel routine in DS manager with the name SayHello.
called that parallel routine from a parallel job
Now I am getting the following sequence of errors
Transformer_107,5: strcat.strcat() at 0xdc97d774
Transformer_107,5: sayhello.strcat(char*,const char*)(??, ??), line 111 in "string.h"
Transformer_107,5: sayhello(char *)(??), line 12 in "sayhello.c"
Note: I tried to compile the C program using one main function and tried to run ...it is working fine in Unix env....
I tried writing my own code for strcat function...It is still giving the same error.....
Can any one please help us in this regard.....
Note: I wrote above sample code for easy to understand...but We need to use strcat function in our project..
Thanks
Sai
Parallel Routine
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Programming Tip
Whenever you use malloc(), use free() when finished with that memory.
If you call this routine one million times, you end up allocating 20MB of memory. This is known as a "memory leak".
You need to test this using a test bed (main() program) and debugger.
Is this usage of malloc() - in an assignment statement - successful?
What happens to the result of strcat()?
Ought you to return a pointer to the string s1?
Whenever you use malloc(), use free() when finished with that memory.
If you call this routine one million times, you end up allocating 20MB of memory. This is known as a "memory leak".
You need to test this using a test bed (main() program) and debugger.
Is this usage of malloc() - in an assignment statement - successful?
What happens to the result of strcat()?
Ought you to return a pointer to the string s1?
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 158
- Joined: Tue Mar 15, 2005 3:16 am
Eric
We wrote parallel routines with the following options
1. Used object as object-type
2. Given External routine name
3. In Library path, we gave the path of the object file(.o)
4. In Type, we gave "External Function"
We used the following Makefile to generate object code
# =====================================================================
# Example Makefile to build the example transformer external functions
#
# AIX version, intended for demonstration purposes only.
#
# =====================================================================
TARGETLIB = libdateValid1.so
CODESRC = main1.c
TARGETOBJ = main1.o
CC = /usr/vacpp/bin/xlC_r
CCOPTIONS = -+ -O -g
LIBCC = $(CC)
LDOPTIONS = -G -qmkshrobj=1000
.SUFFIXES: .c .o
# ---------------------------------------------------------------------
# Rules
# ---------------------------------------------------------------------
all: $(TARGETLIB)
$(TARGETLIB): $(TARGETOBJ)
$(LIBCC) $(LDOPTIONS) $(TARGETOBJ) -o $(TARGETLIB)
$(TARGETOBJ): $(CODESRC)
$(CC) $(CCOPTIONS) -c $(CODESRC) -o $(TARGETOBJ)
clean:
@rm -f $(TARGETOBJ) $(TARGETLIB)
# ---------------------------------------------------------------------
# End of makefile
# ---------------------------------------------------------------------
Assume that the code is in main1.c
Could u pls look into this
Thanks
Sai
We wrote parallel routines with the following options
1. Used object as object-type
2. Given External routine name
3. In Library path, we gave the path of the object file(.o)
4. In Type, we gave "External Function"
We used the following Makefile to generate object code
# =====================================================================
# Example Makefile to build the example transformer external functions
#
# AIX version, intended for demonstration purposes only.
#
# =====================================================================
TARGETLIB = libdateValid1.so
CODESRC = main1.c
TARGETOBJ = main1.o
CC = /usr/vacpp/bin/xlC_r
CCOPTIONS = -+ -O -g
LIBCC = $(CC)
LDOPTIONS = -G -qmkshrobj=1000
.SUFFIXES: .c .o
# ---------------------------------------------------------------------
# Rules
# ---------------------------------------------------------------------
all: $(TARGETLIB)
$(TARGETLIB): $(TARGETOBJ)
$(LIBCC) $(LDOPTIONS) $(TARGETOBJ) -o $(TARGETLIB)
$(TARGETOBJ): $(CODESRC)
$(CC) $(CCOPTIONS) -c $(CODESRC) -o $(TARGETOBJ)
clean:
@rm -f $(TARGETOBJ) $(TARGETLIB)
# ---------------------------------------------------------------------
# End of makefile
# ---------------------------------------------------------------------
Assume that the code is in main1.c
Could u pls look into this
Thanks
Sai
-
- Participant
- Posts: 158
- Joined: Tue Mar 15, 2005 3:16 am
Hi Ray
I understood now the use of free in my program when we run for millions of rows......
But I am not able to understand where to put this free statement....
If u observe our code.....
include<stdio.h>
#include<string.h>
#include<malloc.h>
char * sayhello(char *Arg1)
{
char *s1;
const char *s2="hello";
s1=(char *)malloc(20);
s1="hi";
strcat(s1,s2);
return(s1);
}
If we put free statement before return(s1), s1 will become dangling pointer, where as if we write the free statement after return(s1), the free code is never executed......
Could u help us in this issue also....
Thanks
Sai
I understood now the use of free in my program when we run for millions of rows......
But I am not able to understand where to put this free statement....
If u observe our code.....
include<stdio.h>
#include<string.h>
#include<malloc.h>
char * sayhello(char *Arg1)
{
char *s1;
const char *s2="hello";
s1=(char *)malloc(20);
s1="hi";
strcat(s1,s2);
return(s1);
}
If we put free statement before return(s1), s1 will become dangling pointer, where as if we write the free statement after return(s1), the free code is never executed......
Could u help us in this issue also....
Thanks
Sai
The makefile etc looks good.saikrishna wrote:Eric
We wrote parallel routines with the following options
1. Used object as object-type
2. Given External routine name
3. In Library path, we gave the path of the object file(.o)
4. In Type, we gave "External Function"
Thanks
Sai
when you created the routine definition did you:
- tick the Return Type - char* in the routine definition?
- click on the arguments tab and give the name Arg1 with a native type of char*?