473,385 Members | 2,015 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,385 software developers and data experts.

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 2579
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
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
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
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...
2
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...
42
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
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 =...
42
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
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
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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
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...

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.