The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to return void function pointer umen High Level Programming 1 03-22-2008 01:01 PM
Function Problem and CoreDump ZINGARO Shell Programming and Scripting 8 02-19-2008 03:37 PM
pointer problem useless79 High Level Programming 1 11-07-2007 11:24 PM
PERL function problem avadhani Shell Programming and Scripting 2 06-15-2005 01:18 AM
Problem with the strlen function in ksh steiner Shell Programming and Scripting 3 07-24-2003 05:39 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 10-26-2005
Registered User
 

Join Date: Oct 2005
Posts: 25
Question Problem with function which reutrns pointer to a value

i have a function:
char *pcCityIdToCountryName(ADMIN_DB_DATA *pstHEader, unit uiCityID)

this returns a pointer to CountryName if cityId is given.
to retrieve countryname i give:

char *CountryName;
CountryName = pcCityIdToCountryName(..................);

but when i compile it is giving :
Unresolved
pcCityIdToCountryName

Iam new to C programming. Please help
Reply With Quote
Forum Sponsor
  #2  
Old 10-26-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,271
The compiler (actually the linker) is telling you that it can't find the

char *pcCityIdToCountryName(ADMIN_DB_DATA *pstHEader, unit uiCityID)

code anywhere. Is this function in another module? If so you will have to link against that module.
Code:
cc myfile.c -o myfile -L<some shared library>
or
cc myfile.c somemodule.o -o myfile
The -L syntax requires you to remove the "lib" from in front of the shared library name:
Code:
libcountry.so

becomes:
-L country
The .so or .sl is not needed.
Reply With Quote
  #3  
Old 10-26-2005
Registered User
 

Join Date: Oct 2005
Posts: 25
Thankx for the reply!
As u have said the function is in another file called admin.c, but everything is included in Make file.....
is the statement i have written correct....
does Unresolved means an error... or can it be ignored?????
Reply With Quote
  #4  
Old 10-26-2005
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 4,271
unresolved = fatal error

unresolved means the linker could not find it. The program must have it. The program will not run without it.
Reply With Quote
  #5  
Old 10-26-2005
Registered User
 

Join Date: Oct 2005
Posts: 25
Thank u. I got the solution.
Reply With Quote
  #6  
Old 10-28-2005
mbb mbb is offline
Registered User
 

Join Date: Aug 2001
Location: UK
Posts: 103
Your other post implies you may be passing back a string.

You may prefer to use strcpy like so:

char CountryName[XX*];

strcpy(CountryName, pcCityIdToCountryName(..................) );

*where XX is the size of the string.

The reason being is that you don't know if the char pointer being passed back is still pointing to an allocated memory block. Sometimes I have seen functions pass back a pointer to a local variable or memory being allocated and then made free. It just so happens that you are pointing to a memory location that still has a string (null terminated) value. This may not be the case later on in the program's execution, especially when you are allocating and freeing memory frequently, and you may encounter a memory violation.

At least by copying string into a local variable you can protect against any future problems.

Of course, if it is your own function, you can make your own judgements as to the best way to call it, based on your overall design.
__________________
Senior Analyst/Programmer
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0