473,758 Members | 5,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question about C Functions

If I have the function:

int f(int (*h)(int)) {
return (*h)(13);
}

What exactly does (int (*h)(int)) do? So it's taking a pointer but
what's with the two ints? Thanks.

Nov 1 '06
33 1541
Richard Heathfield wrote:
Default User said:

<snip>

Mr. Heathfield took people to task for what he deemed a worsening
the signal to noise ratio of the group when complaining solely about
top-posting.

Yes, since it was becoming a significant proportion of the traffic.
No, it wasn't. Especially not compared to some of your interminable
arguments with people.
I think what he's doing is every bit as bad

That's your privilege, but (a) the volume isn't actually all that
high, and (b) it has declined rapidly, as I have effectively given up
on the guy ever gaining a clue.
Fine.
(as are his
interminable arguments with Mr. Navia).

I can't help it if the guy is almost always wrong. But in any case,
other people seem to have noticed that he's almost always wrong, so I
don't need to point out his errors quite so often - the load is
distributed more evenly nowadays.
Correcting him on factual matters is a good thing - once. Protracted
arguments aren't. There have been a number of times where I looked at a
newsgroup thread and saw 20 or more posts, the vast majority coming
from two people: Richard Heathfield and Jacob Navia. You can't convince
of anything.

Brian
Nov 4 '06 #31
In article <KV************ *******@news.in digo.ieFrederic k Gotham <fg*******@SPAM .comwrites:
Dik T. Winter:
The following is a bit complicated:
void (*(*f)(int (*)(int)))(int (*)());
cdecl has no problems with it.
....
Now all those f's below are a bit confusing:
(1) f is a pointer.
(2) f is a function whose sole parameter is a pointer to an int-returning-
function whose sole parameter is an int.
(3) f is a pointer.
(4) f is a void-returning-function whose sole parameter is a pointer to an
int-returning-function whose parameter list is void.
(1) and (2) are correct, but this description makes not clear what the
original f does return.
....
It shouldn't be too hard to work with the type now. I'd post example code,
but I can't think of any contrived usage which wouldn't come across as
utterly facetious (given the obscure nature of the type in question).
Obscure? From signal.h under Solaris:
int (*sigset(int, int (*)(int)))(int) ;
I think that declaration has been in there since BSD times. If f were
declared as:
int (*(*(*f)(int (*)(int)))(int, int (*)(int)))(int) ;
it might have been a function that took as parametera sighandler and
returned something of the type of sigset.

cdecl is quite handy at times. For the one I gave above:
cdeclexplain void (*(*f)(int (*)(int)))(int (*)());
declare f as pointer to function (pointer to function (int) returning int)
returning pointer to function (pointer to function returning int)
returning void
cdecl>
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Nov 4 '06 #32
On 4 Nov 2006 00:27:02 GMT, "Default User" <de***********@ yahoo.com>
wrote:
>No, it wasn't. Especially not compared to some of your interminable
arguments with people.
Speaking of interminable arguments, let's stop this one.

--
Al Balmer
Sun City, AZ
Nov 4 '06 #33
Dik T. Winter:
Now all those f's below are a bit confusing:
(1) f is a pointer.
(2) f is a function whose sole parameter is a pointer to an
int-returning- function whose sole parameter is an int.
(3) f is a pointer.
(4) f is a void-returning-function whose sole parameter is a pointer
to an int-returning-function whose parameter list is void.
(1) and (2) are correct, but this description makes not clear what the
original f does return.

That's because the return value is dependant upon the rest of the
breakdown.

It shouldn't be too hard to work with the type now. I'd post example
code, but I can't think of any contrived usage which wouldn't come
across as utterly facetious (given the obscure nature of the type in
question).

Obscure? From signal.h under Solaris:
int (*sigset(int, int (*)(int)))(int) ;

This is far less obscure. It's simply a function which takes a function
pointer and returns one:

typedef int (*FuncPtr)(int) ;

FuncPtr sigset(int,Func Ptr);

--

Frederick Gotham
Nov 4 '06 #34

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

Similar topics

51
4299
by: Casper Bang | last post by:
My question is fundamental I beleive but it has been teasing me for a while: I have two classes in my app. The first class is instantiated as a member of my second class. Within this first class, a method (event) needs to be able to invoke methods of the second class. With static classes its possible but this is not desirable. There's obviouly some visibility problem I am not familiar with. It is not a parent-child relationship since...
3
1672
by: Bryan Parkoff | last post by:
Do C/C++ Compiler allow function to contain more than 8 parameters? I checked MS Visual C++ 6.0 that it can only limit 8 parameters, but most C/C++ Compiler can limit maximum 256 parameters. Can you please verify for me? Usually, I write function that is about 100 lines. I would need 20 parameters which they are all reference to global variable inside struct. For best optimization, it does not require to create stack frame because...
55
2789
by: ben | last post by:
is it true that a function without an inline keyword never get inlined? If not true when is it inlined or not? ben
11
4269
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate threads of a multithreaded program using embedded SQL. Since the threads do not need to share transaction scopes, the sqleAttachToCtx family of APIs do not seem to be necessary. <quote> In the default implementation of threaded applications against...
3
1208
by: Roman Mashak | last post by:
Hello, All! As far as I understand, function declaration with 'static' keyword limits the access to these functions within the file where it declared. So, my question is: where can it be used in real applications? Thanks in advance. With best regards, Roman Mashak. E-mail: mrv@tusur.ru
3
2021
by: Mark Fox | last post by:
Hello, I am porting some old ASP 3.0 VBScript code to C#.NET and am not sure what the equivalent C# functions are for a couple VBScript functions. So my first question is: 1) Is there somewhere that lists old VBScript functions and their equivalent C# functions?
6
2118
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
5
2367
by: Urs Beeli | last post by:
I have a question regarding errno. If I understand it correctly, including <errno.h> allows me to check "errno" for error values that some standard library functions may set. This brings up some questions: - As I understand it, most functions only set errno in an error case. I take this to mean, that on success, errno is not necessarily set to EOK and I would either need to set errno to EOK before calling the function in question to...
7
1876
by: Csaba Gabor | last post by:
I feel like it's the twilight zone here as several seemingly trivial questions are bugging me. The first of the following three lines is a syntax error, while the last one is the only one that shows the alert. What is the essential reason? function () { alert('hi mom'); }(); function () { alert('hi dad'); }(8); var x=function () { alert('hi bro'); }();
12
3018
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
0
9489
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9298
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9737
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7286
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.