12-07-2009
IF I understand - one uses void * as the datatype in function arguments so that it can be cast to a fixed (read: one) datatype in the function.
If you choose to use anonymous blocks in the function, then you could use if() or switch() to select a datatype depending on another variable.
The best choice is to stick with a single datatype. If you need something "cool" use function pointers to branch to the right choice for the datatype you want:
The Function Pointer Tutorials - Syntax
9 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
First and foremost, this is not a homework for your information. I'm just new to using c-shell programming and I just wanted to make my life easier @ work.
Say, the file contains the following:
ID FILE NO. SL VP
1 1 22 33
1 2 ... (3 Replies)
Discussion started by: ilak1008
3 Replies
2. Programming
Hello all
im trying to build function that will return void function pointer
what is mean is ( not working )
the main function
void * myClass::getFunction(int type){
if(type==1)
return &myClass::Test1;
if(type==2)
return &myClass::Test2;
}
void myClass::Test1(){... (1 Reply)
Discussion started by: umen
1 Replies
3. Programming
What is the difference between f(...) , f(void),f()
I know that f(void) doesn't take any parameters, but what about f() and f(...) Does the last call of function even exists? (2 Replies)
Discussion started by: purplelightspar
2 Replies
4. UNIX for Dummies Questions & Answers
void asdf(char *asd)
is this thing a pointer? (1 Reply)
Discussion started by: khestoi
1 Replies
5. Homework & Coursework Questions
Hi All,
My latest assignment (practice not coursework!) is to write prototype interactive exam/test console application. I've used structs to store the question information (not sure if this was the best way to do it?) and I have the following code that outputs each question and it's possible... (0 Replies)
Discussion started by: pondlife
0 Replies
6. Programming
In a well-known book on the C language, there is an example of an efficient method for using a struct member as an argument to a function. (I'm a C noob, but I believe the correct terminology might be: use call-by-reference instead of call-by-value.) The function is printf.
Anyway, here's a... (5 Replies)
Discussion started by: uiop44
5 Replies
7. Programming
hi guys!
Is there such a thing as double void pointer dynamic allocation?
And if so is it something like this?
int n;
void** a;
a=malloc(n*sizeof(void*)); (12 Replies)
Discussion started by: vlm
12 Replies
8. Shell Programming and Scripting
I have 7 functions those need to be executed as command line inputs, I tried with below code it’s not executing function. If I run the ./script 2 then fun2 should execute , how to initiate that function I tried case and if else also, how to initiate function from command line
if
then... (8 Replies)
Discussion started by: saku
8 Replies
9. Programming
I have a function to which I will pass a struct ID and it will return me a string.
I will pass a pointer to store the name string and that pointer will be allocated memory by the function called.
int ConvertIDToName(void *id, void *name, size_t *size)
{
int status = 0;
... (5 Replies)
Discussion started by: rupeshkp728
5 Replies
LEARN ABOUT FREEBSD
bindresvport_sa
BINDRESVPORT(3) BSD Library Functions Manual BINDRESVPORT(3)
NAME
bindresvport, bindresvport_sa -- bind a socket to a privileged IP port
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/types.h>
#include <rpc/rpc.h>
int
bindresvport(int sd, struct sockaddr_in *sin);
int
bindresvport_sa(int sd, struct sockaddr *sa);
DESCRIPTION
The bindresvport() and bindresvport_sa() functions are used to bind a socket descriptor to a privileged IP port, that is, a port number in
the range 0-1023.
If sin is a pointer to a struct sockaddr_in then the appropriate fields in the structure should be defined. Note that sin->sin_family must
be initialized to the address family of the socket, passed by sd. If sin->sin_port is '0' then an anonymous port (in the range 600-1023)
will be chosen, and if bind(2) is successful, the sin->sin_port will be updated to contain the allocated port.
If sin is the NULL pointer, an anonymous port will be allocated (as above). However, there is no way for bindresvport() to return the allo-
cated port in this case.
Only root can bind to a privileged port; this call will fail for any other users.
Function prototype of bindresvport() is biased to AF_INET socket. The bindresvport_sa() function acts exactly the same, with more neutral
function prototype. Note that both functions behave exactly the same, and both support AF_INET6 sockets as well as AF_INET sockets.
RETURN VALUES
The bindresvport() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to
indicate the error.
ERRORS
[EPFNOSUPPORT] If second argument was supplied, and address family did not match between arguments.
The bindresvport() function may also fail and set errno for any of the errors specified for the calls bind(2), getsockopt(2), or
setsockopt(2).
SEE ALSO
bind(2), getsockopt(2), setsockopt(2), ip(4)
BSD
November 22, 1987 BSD