09-28-2009
Function Returning Value w/o return stmt
I am working on a C/Unix application from last 2 years which communicates with other systems using proprietary format of my client. We have a function written in C which returns integer, which is response from other system to the request message initiated by my system. This return value is then assigned to a variable which determines if the transmission was successful or failed. On failure my application is suppose to show some error message to user.
This system has been working proper from long time. We recently got one production issue where application doesn't display error message to user even when communication returns non-zero (Failure!) return code. While analyzing we found that the return statement itself was missing from long time. Now we wonder how the function was returning the correct value working earlier in production w/o return statement.
When we tried to find if there is any change is environment and the only change we could find all the servers who reported issue was recently upgraded to RED HAT Linux 4.0. Now I really don't know how to explain this to client since though this is a fact but I need to have some technical explanation behind this.
Following is the dummy code snippet to explain scenario,
void main ()
{
int responce_code=0;
responce_code=ParseResponse();
if (responce_code != 0)
{
Show_Error();
}
}
int ParseResponse()
{
// We have some parser code to extract the response
log_message("response from other system, %s",respose)
atoi(respose);
}
Now in above statement atoi(respose); should actually be return atoi(respose); in order to get the return code to main(). But still it used to work fine and all of sudden stared failing after upgrade to Red Hat Linux 4 .
It would be great help if some one can explain how this can happen in C for the Linux OS version below RED HAT 4
Thanks in Advance,
Deepak
10 More Discussions You Might Find Interesting
1. Programming
I have two string returning function in ESQL/C
char *segment_name(lbuffer)
char *lbuffer;
{.....
and
char *get_bpdvalue(f_name)
char *f_name;
{......
both declared above main()
char *get_bpdvalue();
char *segment_name();
my problem is segment_name works on sprintf and strcpy... (5 Replies)
Discussion started by: jisc
5 Replies
2. Shell Programming and Scripting
Hi all,
I am very new to BASH shell programming. I need to return an integer from a function to the caller function. I did this:
but it keeps giving me wrong return:
Can someone help me out here, please?
Thanks (2 Replies)
Discussion started by: alirezan
2 Replies
3. Shell Programming and Scripting
Hi All
In my script, I can call on several functions. I have a logging function that is called by any of these functions. What I would like is some way of identifying which function I am using and pass this to the log function as some parameter.
Is there some built in command or way of... (3 Replies)
Discussion started by: kingpin2502
3 Replies
4. Shell Programming and Scripting
I have two scripts. script1.sh looks
--------------------------------
#!/bin/bash
display()
{
echo "Welcome to Unix"
}
display
-----------------------------
Script2.sh
#!/bin/bash
sh script1.sh //simply calling script1.sh
------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies
5. Shell Programming and Scripting
Guys - Simple code, i am trying to get a number back from sqlplus call to a query. After that, i need to use that number in a loop.
---------------------------------
#!/bin/ksh
VALUE=`sqlplus -silent sh/password@sh <<END
set pagesize 0 feedback off verify off heading off echo off
select... (10 Replies)
Discussion started by: sunshine1974
10 Replies
6. Programming
Hi guys.
how a functions such fdopen, ... can return pointer?
are these functions use static memory(variables)? (6 Replies)
Discussion started by: majid.merkava
6 Replies
7. Programming
Hi,
If I have a code like this, what are the potential problems do you see?
const char* const retString() {
return "hello"; /* string literal */
}
My questions are:
a) Since the string literal which is already a constant read only data (cannot be... (4 Replies)
Discussion started by: royalibrahim
4 Replies
8. Shell Programming and Scripting
Hi
I am pretty confused in returning and capturing multiple values
i have defined a function which should return values "total, difference"
i have used as
#!/usr/bin/ksh
calc()
{
total=$1+$2
echo "$total"
diff=$2-$1
echo "$diff"
}
I have invoked this function as
calc 5 8
Now i... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies
9. Shell Programming and Scripting
Not sure where the problem is. I can run the script without any issue using the following command.
. /opt/app/scripts/cdc_migration.sh
But it fails with the below error when I try it this way
/opt/app/scripts/cdc_migration.sh
/opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies
10. Shell Programming and Scripting
Hi All,
Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition.
#Body
function1()
{
if
then
echo "exist"
else
echo "not exist"
}
#if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies
ATOI(3) Linux Programmer's Manual ATOI(3)
NAME
atoi, atol, atoll - convert a string to an integer
SYNOPSIS
#include <stdlib.h>
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
atoll():
__ISOC99_SOURCE ||
|| /* Glibc versions <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE
DESCRIPTION
The atoi() function converts the initial portion of the string pointed to by nptr to int. The behavior is the same as
strtol(nptr, NULL, 10);
except that atoi() does not detect errors.
The atol() and atoll() functions behave the same as atoi(), except that they convert the initial portion of the string to their return type
of long or long long.
RETURN VALUE
The converted value.
ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7).
+------------------------+---------------+----------------+
|Interface | Attribute | Value |
+------------------------+---------------+----------------+
|atoi(), atol(), atoll() | Thread safety | MT-Safe locale |
+------------------------+---------------+----------------+
CONFORMING TO
POSIX.1-2001, POSIX.1-2008, C99, SVr4, 4.3BSD. C89 and POSIX.1-1996 include the functions atoi() and atol() only.
NOTES
Linux libc provided atoq() as an obsolete name for atoll(); atoq() is not provided by glibc.
SEE ALSO
atof(3), strtod(3), strtol(3), strtoul(3)
COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the
latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
GNU
2016-03-15 ATOI(3)