Sponsored Content
Top Forums Programming Function Returning Value w/o return stmt Post 302357092 by jim mcnamara on Monday 28th of September 2009 04:52:50 PM
Old 09-28-2009
First off, compile with gcc -Wall then it won't happen again if you pay attention to warnings. A good compile is zero warnings and zero errors, nothing else is acceptable.

When a function returns an int and nothing is returned by the function - then - whatever garbage data was living on the stack is what gets returned. ie., any value is possible. If your code looks like
Code:
int retval=0;
retval=myfunc();
if(retval)
   // good return
else
  // zero == error return

Then any garbage on the stack will result in a "good" return. This is called programming by coincidence, in polite circles, when it actually works.
 

10 More Discussions You Might Find Interesting

1. Programming

string returning function

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

returning from a function

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

Returning the name of function used

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

Return a value from called function to the calling function

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

sqlplus returning value - remove carriage return '\r' - Please help

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

Function Returning Pointer

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

Returning local string value from a function in C

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

Returning and capturing multiple return values from a function

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

Return: can only `return' from a function or sourced script

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

Function - Make your function return an exit status

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
VOP_PATHCONF(9) 					   BSD Kernel Developer's Manual					   VOP_PATHCONF(9)

NAME
VOP_PATHCONF -- return POSIX pathconf information SYNOPSIS
#include <sys/param.h> #include <sys/vnode.h> #include <sys/unistd.h> int VOP_PATHCONF(struct vnode *vp, int name, int *retval); DESCRIPTION
The arguments are: vp The vnode to get information about. name The type of information to return. retval The place to return the information. The value of name specifies what should be returned: _PC_LINK_MAX The maximum number of links to a file. _PC_NAME_MAX The maximum number of bytes in a file name. _PC_PATH_MAX The maximum number of bytes in a pathname. _PC_PIPE_BUF The maximum number of bytes which will be written atomically to a pipe. _PC_CHOWN_RESTRICTED Return 1 if appropriate privileges are required for the chown(2) system call, otherwise 0. _PC_NO_TRUNC Return 1 if file names longer than KERN_NAME_MAX are truncated. RETURN VALUES
If name is recognized, *retval is set to the specified value and zero is returned, otherwise EINVAL is returned. SEE ALSO
pathconf(2), vnode(9) AUTHORS
This manual page was written by Doug Rabson. BSD
July 24, 1996 BSD
All times are GMT -4. The time now is 07:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy