Sponsored Content
Top Forums Programming how to catch a parameter that is of the wrong type Post 302069411 by jim mcnamara on Saturday 25th of March 2006 05:54:57 AM
Old 03-25-2006
C doesn't provide a way to check the datatype of an argument, which is why the compiler does it. variable argument lists are an exception to this.

It is the responsibility of the calling function to make sure the arguments are correct - in this case.

For example, printf() is in the same boat that your function is. It will print garbage or even segfault in this case:

Code:
double z=13.1;
printf("%s\n",z);

Note that printf cannot check to see if "z" is a character array. You code has the same issue.
[/code]
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

wrong parameter passing!

Hi all I have a script which will take input as filename and passes it to a java program. It is as follows -------------------------------- FILENAME=$1 echo $FILENAME ${JAVA_HOME}/bin/java -cp DateProvider $FILENAME ------------------------------------------------- when I execute the same... (2 Replies)
Discussion started by: malle
2 Replies

2. Shell Programming and Scripting

how do I make dynamic parameter names? Or get the value of a parameter evaluated twi

Say I write something like the following: var1=1 var2=2 for int in 1 2 do echo "\$var$int" done I want the output to be: 1 2 Instead I get something like: $var1 $var2 (2 Replies)
Discussion started by: Awanka
2 Replies

3. Shell Programming and Scripting

String type to date type

Can one string type variable changed into the date type variable. (1 Reply)
Discussion started by: rinku
1 Replies

4. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

5. UNIX for Advanced & Expert Users

register parameter type

Hello, I like to register parameters of my programm to the shell (for tab usage). How to do that? (3 Replies)
Discussion started by: daWonderer
3 Replies

6. Shell Programming and Scripting

Command that takes one parameter and then searches for the passed in parameter

Hi I am looking for a unix command or a small shell script which can takes one parameter and then searches for the passed in the parameter in any or all files under say /home/dev/ Can anyone please help me on this? (3 Replies)
Discussion started by: pankaj80
3 Replies

7. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

8. Shell Programming and Scripting

Why result is wrong here ? whether break statement is wrong ?

Hi ! all I am just trying to check range in my datafile pls tell me why its resulting wrong admin@IEEE:~/Desktop$ cat test.txt 0 28.4 5 28.4 10 28.4 15 28.5 20 28.5 25 28.6 30 28.6 35 28.7 40 28.7 45 28.7 50 28.8 55 28.8 60 28.8 65 28.1... (2 Replies)
Discussion started by: Akshay Hegde
2 Replies

9. Shell Programming and Scripting

What is wrong with 'find . -maxdepth 1 -ctime -7 -type f'?

Have you tried running the command below? On the same RHEl 6.8 or 6.6. It will give you different output. find . -maxdepth 1 -ctime -7 -type f rpm -qa|grep find findutils-4.4.2-9.el6.x86_64 # cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.8 (Santiago) # (6 Replies)
Discussion started by: invinzin21
6 Replies
va_arg(9F)						   Kernel Functions for Drivers 						va_arg(9F)

NAME
va_arg, va_start, va_copy, va_end - handle variable argument list SYNOPSIS
#include <sys/varargs.h> void va_start(va_list pvar, void parmN); (type *) va_arg(va_list pvar, type); void va_copy(va_list dest, va_list src); void va_end(va_list pvar); INTERFACE LEVEL
Solaris DDI specific (Solaris DDI). PARAMETERS
va_start() pvar Pointer to variable argument list. name Identifier of rightmost parameter in the function definition. va_arg() pvar Pointer to variable argument list. type Type name of the next argument to be returned. va_copy() dest Destination variable argument list. src Source variable argument list. va_end() pvar Pointer to variable argument list. DESCRIPTION
This set of macros allows portable procedures that accept variable argument lists to be written. Routines that have variable argument lists but do not use the varargs() macros are inherently non-portable, as different machines use different argument-passing conventions. Routines that accept a variable argument list can use these macros to traverse the list. va_list is the type defined for the variable used to traverse the list of arguments. va_start() is called to initialize pvar to the beginning of the variable argument list. va_start() must be invoked before any access to the unnamed arguments. The parameter name is the identifier of the rightmost parameter in the variable parameter list in the function defi- nition (the one just before the ", ..."). If this parameter is declared with the register storage class or with a function or array type, or with a type that is not compatible with the type that results after application of the default argument promotions, the behavior is undefined. va_arg() expands to an expression that has the type and value of the next argument in the call. The parameter pvar must be initialized by va_start(). Each invocation of va_arg() modifies pvar so that the values of successive arguments are returned in turn. The parameter type is the type name of the next argument to be returned. The type name must be specified in such a way that the type of pointer to an object that has the specified type can be obtained by postfixing a * to type. If there is no actual next argument, or iftype is not compatible with the type of the actual next argument (as promoted according to the default argument promotions), the behavior is undefined. The va_copy() macro saves the state represented by the va_list src in the va_list dest. The va_list passed as dest should not be initial- ized by a previous call to va_start() It then must be passed to va_end() before being reused as a parameter to va_start() or as the dest parameter of a subsequent call to va_copy(). The behavior is undefined if any of these restrictions are not met. The va_end() macro is used to clean up. It invalidates pvar for use (unless va_start() is invoked again). Multiple traversals, each bracketed by a call to va_start() and va_end(), are possible. EXAMPLES
Example 1: Creating a Variable Length Command The following example uses these routines to create a variable length command. This might be useful for a device that provides for a vari- able-length command set. ncmdbytes is the number of bytes in the command. The new command is written to cmdp. static void xx_write_cmd(uchar_t *cmdp, int ncmdbytes, ...) { va_list ap; int i; /* * Write variable-length command to destination */ va_start(ap, ncmdbytes); for (i = 0; i < ncmdbytes; i++) { *cmdp++ = va_arg(ap, uchar_t); } va_end(ap); } SEE ALSO
vcmn_err(9F), vsprintf(9F) NOTES
It is up to the calling routine to specify in some manner how many arguments there are, since it is not always possible to determine the number of arguments from the stack frame. Specifying a second argument of char or short to va_arg makes your code non-portable, because arguments seen by the called function are not char or short. C converts char and short arguments to int before passing them to a function. SunOS 5.10 21 Feb 1996 va_arg(9F)
All times are GMT -4. The time now is 09:52 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy