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

pointer in union

A very basic question...may be...
i have defined an uinion

//***************************
union AllDataTypes
{
unsigned char value_char;
unsigned int value_int;
unsigned long value long;
float value_float;
unsigend char* value_ptr;
}temp;
/*****************************

how would i use "value_ptr"....i want to update the pointing location.

thnx,
dimple
Jul 1 '07 #1
1 3284
weaknessforcats
9,208 Expert Mod 8TB
You use the union like a struct:
Expand|Select|Wrap|Line Numbers
  1. unsignedchar ch;
  2. AllDataTypes  data;
  3. data.value_ptr = &ch;
  4.  
Remember a union has only one member at a time. The same memory is used by all members so it is up to you to know what member to use.

You may want a discriminator.

Check out the Microsoft VARIANT. It does what you are starting to do and uses a discriminator. Google should produce the code.
Jul 1 '07 #2

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

Similar topics

3
by: Robert Street | last post by:
Hi! I'm rather new at c++ and I'm totally confused with this kind of typecasting: typedef signed char int8_t; typedef signed short int16_t; typedef struct broadcast_hdr {
4
by: Steven T. Hatton | last post by:
I mistakenly set this to the comp.std.c++ a few days back. I don't believe it passed the moderator's veto - and I did not expect or desire anything different. But the question remains: ISO/IEC...
6
by: Jim Ford | last post by:
I wonder if the following is possible: I would like to have a function with, say, three arguments. The first two would be int, whereas the third one would be a pointer to a generic function. By...
41
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
1
by: qwerty2_reverse_iterator | last post by:
Is this a bug with the ms compiler (V7.1)? (It seems so at least.) I get errors when I don't initialize all the const pointer fields of an anonymous union in a struct. Example: //T2.h...
23
by: Eric J.Hu | last post by:
Hi, I have following code, want do pointer convert. It always complain: vcnvt.c: In function `main': vcnvt.c:20: warning: dereferencing `void *' pointer vcnvt.c:20: request for member `key'...
3
by: Rennie deGraaf | last post by:
Let's say that I want to read a method pointer in from a stream. (I'm not saying that this is a good design idea, or that I actually have a reason to do this.) If I wanted to read in a function...
12
by: Nyang A. Phra | last post by:
I have following code: union Pointer { void *objp; void (*funcp)(); }; Pointer p = ... ; ....
4
by: Bryan Parkoff | last post by:
We discussed about the union keyword on the previous threads 2-3 days earlier. I want to add. Two byte data inside struct and one word data are inside union. You modify word data. Then two byte...
26
by: eotcl | last post by:
Dear Group! Is it possible to dereference the void pointer to function pointer, and refer to this pointer later as if it was a function. Thanks.
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: 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
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:
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
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
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
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.