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

union elements

union Allrecords* rec;

how would i get the size of Allrecords;
and how would I dynamically create memory for rec? I tried using the operator
new
with no success.
Jul 22 '05 #1
2 1264
On 19 Feb 2004 04:07:05 GMT in comp.lang.c++, ja*******@aol.com
(JasBascom) was alleged to have written:
union Allrecords* rec;

how would i get the size of Allrecords;
With the sizeof operator, I suppose. Why would you want to know it?
It seems fairly unlikely that you should care about that. What are you
trying to accomplish?

Probably best to avoid pointers and new for most purposes.
I tried using the operator new with no success.


This issue is covered in Marshall Cline's C++ FAQ. See the topic
"[5.8] How do I post a question about code that doesn't work correctly?"
It is always good to check the FAQ before posting. You can get the FAQ
at:
http://www.parashift.com/c++-faq-lite/

Jul 22 '05 #2

"JasBascom" <ja*******@aol.com> wrote in message
news:20***************************@mb-m07.aol.com...
union Allrecords* rec;

how would i get the size of Allrecords;
If you want to know the size of a single Allrecords object, use
sizeof(Allrecords). If you have an object of type Allrecords*, and you
want to know whether it points to an array, and if so, the size of the
array, you're out of luck. You have to keep track of this info
yourself.

What do unions have to do with anything here?
and how would I dynamically create memory for rec? I tried using the operator new
with no success.


Operator new is the way to go for dynamic allocation. What happened
when you tried?

Jonathan

Jul 22 '05 #3

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

Similar topics

2
by: Dave Smithz | last post by:
Hi there. Because of the lack of a Union query in MySQL 3 I have decided to take the approach where I populate two arrays with values from similar tables in DB. In this case they are `courses`...
4
by: shaun palmer | last post by:
when or Where do you use a union query ? how can I wright sql, tblPopulation,* tblcustomer,* one to one with all the appropriate attributes(field). Your help would be greatly...
4
by: csudha | last post by:
Hi All, Can you give me the example code which explains difference between Structures and Union. As a newbie please do the needful. Thanks, csudha.
18
by: Mockey Chen | last post by:
My friend ask me a question as following: give a union SU define as: typedef union _SU { short x; struct y{ char a; short b; char c;
16
by: tedu | last post by:
does anyone know of a platform/compiler which will place union elements to not overlap? as in union u { int a; long b; size_t c; }; in my limited experience, writing to any of (a, b, or c)...
8
by: wkaras | last post by:
In my compiler, the following code generates an error: union U { int i; double d; }; U u; int *ip = &u.i; U *up = static_cast<U *>(ip); // error I have to change the cast to...
30
by: Yevgen Muntyan | last post by:
Hey, Why is it legal to do union U {unsigned char u; int a;}; union U u; u.a = 1; u.u; I tried to find it in the standard, but I only found that
8
by: Latina | last post by:
Hi, I am doing a program of overloaded methods. I want to get what is the union of the user set and S set and the user set and S1 set. I try it but it is not working. Can some one help me please?...
18
by: Bryan Parkoff | last post by:
I hate using struct / union with dot between two words. How can I use one word instead of two words because I want the source code look reading clear. three variables are shared inside one...
12
by: Roman Mashak | last post by:
Hello, I'm going through the "UNIX network programming" by R.Stevens and stuck with the following code, determining the endiannes of a host it is running on: #include <stdio.h> #include...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.