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

Declare variable type void *

If I declare a variable to be type void * how do I assign values to it (int, float, and char ) and how do I read the variable.

Thanks
May 27 '08 #1
4 7206
sicarie
4,677 Expert Mod 4TB
You cannot declare variables of type void
May 27 '08 #2
weaknessforcats
9,208 Expert Mod 8TB
void means no type. A void* describes a pointer variable that points to no type. That is, it is just an address.

You should be able to assign the address of any type to void* but you shoule get errors assgining the address in a void* to a pointer to a real type unless you typecast.

In any case, you cannot assign the value of an int, float, etc to a void* since those types contain actual values and not addresses.

The above comment applies to C. In C++ you do not use void*. There are templates for that.
May 27 '08 #3
More info: I have a function
int ffpky(fitsfile *fptr, int datatype, char *keyname, void *value,
char *comm, int *status);
The data type tells the routine what it's getting: int, float etc.
In the calling program which I'm pretty sure is in c: How do I get an int, float, or string into value.

thanks.
May 27 '08 #4
Thanks. I think I got it.



void means no type. A void* describes a pointer variable that points to no type. That is, it is just an address.

You should be able to assign the address of any type to void* but you shoule get errors assgining the address in a void* to a pointer to a real type unless you typecast.

In any case, you cannot assign the value of an int, float, etc to a void* since those types contain actual values and not addresses.

The above comment applies to C. In C++ you do not use void*. There are templates for that.
May 27 '08 #5

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

Similar topics

6
by: David T. Ashley | last post by:
Hi, In my project, I typically declare and define variables in the .H file, i.e. DECMOD_MAIN UINT8 can_message_201_status_global #ifdef MODULE_MAIN = HAS_NEVER_BEEN_RECEIVED #endif ;
7
by: Irish | last post by:
Hello all :) Hopefully someone can shed some light on this problem I'm having. I'm trying to declare a variable to a type of class I've defined (which is a minHeap), but actually instantiate it...
14
by: sathya_me | last post by:
Dear clc, I have a variable void *a; Since variable "a" can be assigned (point to) any type and also any type can be assigned to "a" (i.e means "a" = any typed variable; any typed variable =...
15
by: Geoff Cox | last post by:
Hello, Can I separately declare and initialize a string array? How and where would I do it in the code below? It was created using Visual C++ 2005 Express Beta 2 ... In C# I would have ...
1
by: ares.lagae | last post by:
- I have a typelist and I want to declare a member variable for each of the types. How can I do that? E.g. I have the typelist "typedef boost::mpl::vector<int, float> types;" and I want to declare...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
2
by: beet | last post by:
Hi all, I tried to declare a c++ struct like following in a header file: ------ 1 #ifndef _SEARCHDATA_H_ 2 #define _SEARCHDATA_H_ 3 4 #include <vector> 5 #include <list>
7
by: bashill.zhu | last post by:
bzhu@TY-PC /h/working/tcplex/ch8/testenum $ cat lexer.h namespace Lexer { enum Token_value; extern Token_value string_value; void get_token(); } bzhu@TY-PC /h/working/tcplex/ch8/testenum
1
by: yu83thang | last post by:
Hi, May I know how to declare a Class in C++ window application form? Below is my code and error as shown below as well. here is my class declaration: ref class CLoadObj { public:
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
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
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,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.