473,704 Members | 2,442 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

universal pointer to restricted pointer

rz0
Hi,

I have a function that takes a callback function (function pointer of
some type) and a value to be passed to it when it is invoked later. The
prototype looks pretty much like :

int reg(int (*)(void *), void *);

Now, it appears that most of the values (second argument) I want to
register have types of the form T * restrict *, that is, a pointer to
a restricted pointer to some type T. Since there is no implicit
conversion to void *, I have to cast each time I make a call to the
registration function.

I would like to have a different prototype for such cases so the cast
becomes unecessary. If it were const, then using const void * would be
a solution but restrict cannot be applied to void. Is there any elegant
alternative to the problem ?

Thanks
Apr 26 '06 #1
1 2591
rz0 wrote:
Hi,

I have a function that takes a callback function (function pointer of
some type) and a value to be passed to it when it is invoked later. The
prototype looks pretty much like :

int reg(int (*)(void *), void *);

Now, it appears that most of the values (second argument) I want to
register have types of the form T * restrict *, that is, a pointer to
a restricted pointer to some type T. Since there is no implicit
conversion to void *, I have to cast each time I make a call to the
registration function.

I would like to have a different prototype for such cases so the cast
becomes unecessary. If it were const, then using const void * would be
a solution but restrict cannot be applied to void. Is there any elegant
alternative to the problem ?

Thanks


If the second argument is always of same type, why cant you use that
type for the second actual argument ?
Otherwise if it differs in some cases, I think you can make use of
variable length argument lists in this case. I dont know how elegant
this solution is. But it will be useful, since you can avoid casting
the second argument in the call and do it inside your function.

Regards,
arun..

Apr 27 '06 #2

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

Similar topics

11
1700
by: Vladimir | last post by:
Hello! I'd like to select one of possible entities according to a given index: select(index, A, B) would return A if index is 0, B if index is (or greater than) 1. so i write:
79
125223
by: syntax | last post by:
what is the size of a pointer? suppose i am writing, datatype *ptr; sizeof(ptr); now what does this sizeof(ptr) will give? will it give the size of the
5
2587
by: Peter Ammon | last post by:
It's my understanding that the printf() function is declared as int printf(const char * restrict format, ...); in stdio.h. And loosely speaking, if a parameter is declared as restricted, then accesses to the object must go through that parameter. Does this mean that printf("%s", "%s");
2
2217
by: Anouar | last post by:
The point was to make a program that gives you the possibilty to enter a sentence and when you press "enter" it should ask a number for example when i press 4 It should take the 4th word out of the sentence and print it example sentence "hello i am Anouar" the space after hello should not be a problem for the program so whe i ask for the second word it should give "i" for an answer.. this is what i've got so far
42
5613
by: baumann | last post by:
hi all, typedef int (*pfunc)(int , int); pfunc a_func; i know it's ok, but how can define a_func without typedef statement? thanks .
204
13026
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 = {0,1,2,4,9};
42
5326
by: xdevel | last post by:
Hi, if I have: int a=100, b = 200, c = 300; int *a = {&a, &b, &c}; than say that: int **b is equal to int *a is correct????
3
1734
by: George2 | last post by:
Hello everyone, In the following statements, template <class R, class Tclass mem_fun_t : public unary_function <T*, R> {
5
3909
by: jason.cipriani | last post by:
There have been some recent threads about casting pointers to and from void* that have me rethinking some of my usual practices. I have a couple of questions. 1. What is the purpose of C++'s static_cast<>? In other words, is there any real difference between statements like (with non-pointer types): double a = 3.4; int b = (int)a; // <--- this
0
8767
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
8688
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
9135
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
9029
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,...
1
6605
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
5932
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
4702
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3136
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.