473,396 Members | 1,913 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,396 software developers and data experts.

Weird Function Calling

11
I have a function defined and called by main program as follows:

defined: int function_name (int)

Called upon: (int (*)(int)) function_name

Could anyone shed some light regarding the above? The program could be compiled and executed.
Mar 6 '08 #1
2 1079
weaknessforcats
9,208 Expert Mod 8TB
Yes, it is weird.

This is a typecast:
Expand|Select|Wrap|Line Numbers
  1. (int (*)(int)) function_name
  2.  
just like
Expand|Select|Wrap|Line Numbers
  1. (int*)data
  2.  
So, function_name is the name of a function. As such, the function name is also the address of the function. In this case, function_name is the address of a function that takes an int argument and returns an int.

The typecast is casting function_name as the address of a function that takes an int argument and returns an int.

The weird part is that it already is that kind of address.

I suspect you can remove (int (*)(int)) function_name from your code and things will still work.
Mar 6 '08 #2
JonLT
41
It's a function pointer
Expand|Select|Wrap|Line Numbers
  1. (int (*)(int))
means a pointer to a function that returns an int and takes an int as an argument.

EDIT: isn't it?
Mar 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Betty Perea | last post by:
I'm having a little weird condition. I have a simple form (POST method), whose Action is a validation script, most of the times it works. But sometimes, the validation script does not "receive"...
3
by: Alex Shi | last post by:
Hi all, Please take a look at following very simple script; #!/usr/bin/php -q <? echo "Hello, world!\n"; if (!$tty) { $tty = fopen('php://stdin', 'r'); }
1
by: Pelle | last post by:
Hello all, I have to admit, that the idea that occurred to me recently is weird. It was somehow inspired by the huge response on the "delete operator" thread, but goes into a somewhat different...
11
by: Anon Email | last post by:
Hey people, This looks really weird. I can't make sense of it. Is this a mistake? Can anyone help? IStack const & GetStack () const; Cheers,
14
by: Nak | last post by:
Hi there, It's probably me being weird more than the function but I'm having problems with it doing as it should. I have a C++ application with 2 resources of custom types, RT_INIFILE @...
2
by: Rob T | last post by:
I have a collection of objects that I'm using to keep track of general ledger (GL) entires. Each object in the collection is one GL entry. I then have a function that will add up all the debits...
4
by: Bo Peng | last post by:
Dear list, I spent the last 12 hours in catching this bug (?) and what I found out is very difficult to explain: Basically, I need to call a user-provided function many times, with a tuple as...
4
by: Peter Afonin | last post by:
Hello, I have a weirdest issue I've ever had. I have a function that enters some data into the Oracle table and returns the sequential row number for the new record (autonumber): Private...
29
by: Ancient_Hacker | last post by:
A while back I had to recompile some old code, originally written by a really good programmer, but one prone to use every trick in the book, and then some. There was a statement, something like...
14
by: WStoreyII | last post by:
the following code is supposed to read a whole line upto a new line char from a file. however it does not work. it is producing weird results. please help. I had error checking in there for...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.