473,322 Members | 1,540 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,322 software developers and data experts.

accessing comon initial sequence in union

Quote from 6.5.2.3 Structure and union members, Examle 3:
The following is not a valid fragment (because the union
type is not visible within function f):

struct t1 { int m; };
struct t2 { int m; };
int f(struct t1 * p1, struct t2 * p2)
{
if (p1->m < 0)
p2->m = -p2->m;
return p1->m;
}
int g()
{
union {
struct t1 s1;
struct t2 s2;
} u;
/* ... */
return f(&u.s1, &u.s2);
}
Would the code become valid if we expanded function f inside g?
struct t1 { int m; };
struct t2 { int m; };
int g()
{
union {
struct t1 s1;
struct t2 s2;
} u;
struct t1 * p1;
struct t2 * p2;
/* ... */
p1 = &u.s1;
p2 = &u.s2;
if (p1->m < 0)
p2->m = -p2->m;
return p1->m;
}
This seems to satisfy 6.5.2.3#5 ("One special guarantee..."): the union
declaration is visible throughout the function g; but I feel this code
is still wrong.

--
Stan Tobias
sed 's/[A-Z]//g' to email
Nov 14 '05 #1
0 1319

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

Similar topics

1
by: Steve Morrell | last post by:
Hi there, I'm trying to write a piece of sql to set an Oracle sequence's nextval to a number specified my the max value in a set of columns. The sequence is populating these columns, so I want...
5
by: ratu | last post by:
I'd like to use a stored procedure to insert large amounts of records into a table. My field A should be filled with a given range of numbers. I do the following ... but I'm sure there is a better...
27
by: Daniel Lidström | last post by:
Hello! I want to work with individual bytes of integers. I know that ints are 32-bit and will always be. Sometimes I want to work with the entire 32-bits, and other times I want to modify just...
2
by: Barry Schwarz | last post by:
Given a union of the form union { T1 m1; T2 m2;}obj; where T1 and T2 are different scalar (non-aggregate) types. The C99 standard states that obj.m1 = value; if (obj.m2 ... invokes...
47
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to...
4
by: Sim Zacks | last post by:
I am in the process of converting an existing database to PostGreSQL and wrote a generic script to update all of the sequences as they default at 1. I thought it would be useful to other people who...
7
by: urban.widmark | last post by:
Hello We are having some problems with triggers, sequences and union all in V8 on code that worked fine in V7. Was wondering if someone else has seen this and/or knows what to do. A trigger...
1
by: aarklon | last post by:
Hi folks, Recently i was reading the book C an advanced introduction by narain gehani, in page no:236 it is written as If a union contains several structures with a common initial sequence,...
5
by: pt | last post by:
Hi, i am wonderng what is faster according to accessing speed to read these data structure from the disk in c/c++ including alignment handling if we access it on little endian system 32 bits...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.