473,405 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

what does this statement means?

return &dhcpInit;

where dhcpInit() is a function decleared before.
would dhcpInit be called?

Nov 16 '06 #1
1 1315
Readon Shaw said:
return &dhcpInit;

where dhcpInit() is a function decleared before.
would dhcpInit be called?
No. The name of a function is converted into a pointer to that function. In
that particular case, & is redundant. The code could equally have said:

return dhcpInit;

In either case, the function is not called, but its address is returned to
the caller. The caller can then invoke that function through the pointer.

Example follows:

#include <stdio.h>

void foo(void)
{
puts("I'm foo!");
}

void bar(void)
{
puts("I'm bar!");
}

typedef void vvfunc(void);

vvfunc *choose(int n)
{
vvfunc *ptr = foo;
if(n % 2 == 1) /* how odd */
{
ptr = bar;
}
return ptr;
}

int main(void)
{
int i = 0;
int j = 1;
int k = i + j;
vvfunc *f;
do
{
printf("%d ", i);
f = choose(i); /* get a pointer to a function */
(*f)(); /* call that function */
i = j;
j = k;
k = i + j;
} while(i < 1000);
return 0;
}

Running this program gives the following output:

0 I'm foo!
1 I'm bar!
1 I'm bar!
2 I'm foo!
3 I'm bar!
5 I'm bar!
8 I'm foo!
13 I'm bar!
21 I'm bar!
34 I'm foo!
55 I'm bar!
89 I'm bar!
144 I'm foo!
233 I'm bar!
377 I'm bar!
610 I'm foo!
987 I'm bar!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
Nov 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
8
by: Kim Forbes | last post by:
I am learning Javascript; and most books only give you partial definitions for the functions they show you. Here is a line of code from a browser sniffing function: var isWin =...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
38
by: larry | last post by:
I am looking at some code which process an uploaded file and it has loops like: for(;;){ // for([two semicolons){ what is the function of the two semicolons? loop until break? I've...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.