To the best of my knowledge, you always have to tell C functions something about their parameters. Taking your example: the function execute should take an arbitrary number of arguments of unknown type, right? So lets say you pass along
an int*: is it a pointer to an integer, or just the start of an integer array? If it's the later, how should it know how far to count?
an int: is it a number, an address, or the starting address of an array? If it's an address, what's there? A char/long/double?
As you've said, you've got a number and a list of parameters. Is the number the number of parameters in the list? If so, just use the va_* macros for a function:
or even better
If that doesn't suit you, could you give an better example of what you need?
Hi, Can anyone help me figure out the problem I'm having with a function call?
I have a header file, which sets an enum:
typedef enum {INFO, WARNING, FATAL} Levels;
int log_event (Levels, char *fmt, ...);
..then the function is called this way:
log_event(INFO, "Message text");
... (6 Replies)
I have a function check_ok in my abc.sh. which return me 1 or 0 . I want to call this fuction through other shell script. this shell also send two parameter to calling function.
Can you please tell me how. I am very new in unix.
#!/bin/bash
date_equal()
{
sqlplus -silent... (4 Replies)
hello,
when i call function inside awk traitement it doesn't work, i don't have error execution but i don't get result and if i call the function outside awk traitement it work well..
there's something special in awk call function??
here is the example :
awk -F "," '{ {first=$1; sec=$2;... (3 Replies)
Hello,
I have a problem with package and name space.
require "/Mehran/DSGateEngineLib/general.pl";
use strict;
sub System_Status_Main_Service_Status_Intrusion_Prevention
{
my %idpstatus;
my @result;
&General_ReadHash("/var/dsg/idp/settings",\%idpstatus);
#print... (4 Replies)
Hi foiks
i am unable to find what is wrong in my code
mu functionality is to exit from shell when i give 99 but it is not calling function ext
Could you please correct me.
read option
if ;
then
ext
else
echo "out"
fi
function ext
{
echo "tested 99 and exit... (12 Replies)
Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this?
iNOUT i AM GIVING TO THE... (1 Reply)
Hi all,
Does anyone know if it possible to append a parameter to a function name?
Something like the following:
function tnsrec_${SERVICE_NAME} {
code..
}
Any ideas? (6 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
2. Relevant commands, code, scripts, algorithms:
#! /bin/ksh
v="ORG_ID"
... (2 Replies)
Discussion started by: sujitdas2104
2 Replies
LEARN ABOUT OSF1
va_end
varargs(3) Library Functions Manual varargs(3)NAME
varargs, va_arg, va_start, va_end - Handles a variable-length parameter list
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <varargs.h>
va_alist va_dcl void va_start ( va_alist argp ); type va_arg ( va_alist argp, type ); void va_end ( va_alist argp );
PARAMETERS
argp Specifies a variable that the varargs macros use to keep track of the current location in the parameter list. Do not modify this
variable.
type Specifies the type to which the expected argument will be converted when passed as an argument. Unsigned char or short arguments
are converted to unsigned int, and float arguments are converted to double. Different types can be mixed, but it is up to the rou-
tine to know what type of argument is expected because the type cannot be determined at run time.
DESCRIPTION
NOTE: When writing new code, it is recommended that you use stdarg instead of varargs. They both perform the same function, but stdarg is
standards-compliant and varargs complies only with BSD conventions.
The varargs set of macros allows you to write portable functions that accept a variable number of parameters. Subroutines that have vari-
able-length parameter lists (such as the printf() function), but that do not use the varargs macros, are inherently nonportable because
different systems use different parameter-passing conventions.
The varargs macros are as follows:
va_alist()
Defines the type of the variable used to traverse the list.
va_start()
Initializes argp to point to the beginning of the list. The va_start() macro will be invoked before any access to the unnamed argu-
ments.
va_arg()
Returns the next parameter in the list pointed to by argp.
va_end()
Cleans up at the end.
Your function can traverse, or scan, the parameter list more than once. Start each traversal with a call to va_start() and end it with
va_end().
EXAMPLE
The following example is a possible implementation of the execl() function:
#include <varargs.h>
#define MAXargS 100
/*
** execl is called by
** execl(file, arg1, arg2, . . . , (char *) 0);
*/
execl(va_alist)
va_dcl
{ va_list ap;
char *file;
char *args[MAXargS];
int argno = 0;
va_start(ap);
file = va_arg(ap, char *);
while ((args[argno++] = va_arg(ap, char *)) != (char *) 0)
; /* Empty loop body */
va_end(ap);
return (execv(file, args));
}
NOTES
The calling routine is responsible for specifying the number of parameters because it is not always possible to determine this from the
stack frame. For example, the execl() function is passed a null pointer to signal the end of the list. The printf() function determines the
number of parameters from its fmt parameter.
AES Support Level: Temporary use
RELATED INFORMATION
Functions: exec(2), printf(3), stdarg(3), vprintf(3) delim off
varargs(3)