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

Sequence point question

Hello all. I do not have access to the ANSI standard doc. Perhaps
someone can help me with this. Suppose I have this situation:

typedef void *PTR;

struct cons_s {
PTR car, cdr;
};

struct root_record_s {
...
struct cons_s *p;
};

PTR cons(struct root_record_s *rr, PTR car, PTR cdr)
{
...
rr->p->cdr = gc_malloc(rr, sizeof(struct cons_s));
...
}

where gc_malloc may change the value of rr->p. Is there anything in
the ANSI standard that says rr->p->cdr will be the "correct" l-value,
e.g. the new one after gc_malloc() makes the change? Or must the
assignmet be split into two to ensure correct sequencing? ...

PTR cons(struct root_record_s *rr, PTR car, PTR cdr)
{
PTR tmp;
...
tmp = gc_malloc(rr, sizeof(struct cons_s));
rr->p->cdr = tmp;
...
}

Many thanks.

Jun 23 '07 #1
5 1195
Gene wrote:
rr->p->cdr = gc_malloc(rr, sizeof(struct cons_s));

where gc_malloc may change the value of rr->p. Is there anything in
the ANSI standard that says rr->p->cdr will be the "correct" l-value,
e.g. the new one after gc_malloc() makes the change?
No.
Or must the
assignmet be split into two to ensure correct sequencing?
Yes. Even though calling a function results in sequences points, the
point at which rr->p is evaluated is unspecified with regard to when the
function is called.

--
Thad
Jun 23 '07 #2
Gene said:
Hello all. I do not have access to the ANSI standard doc. Perhaps
someone can help me with this. Suppose I have this situation:
<snip>
PTR cons(struct root_record_s *rr, PTR car, PTR cdr)
{
...
rr->p->cdr = gc_malloc(rr, sizeof(struct cons_s));
...
}

where gc_malloc may change the value of rr->p. Is there anything in
the ANSI standard that says rr->p->cdr will be the "correct" l-value,
e.g. the new one after gc_malloc() makes the change?
No, 'fraid not. As you thought, you have to use a temp to be sure of the
code doing what you want.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 23 '07 #3
Gene wrote, On 23/06/07 05:20:
Hello all. I do not have access to the ANSI standard doc. Perhaps
<snip>

If you go to http://clc-wiki.net/wiki/c_standard there are links to
where you can obtain drafts of the various versions of the C standard
and information about the different types, including why I use the ISO
(or BSI) standard rather than the ANSI one.

Others have answered your main question correctly so I won't.
--
Flash Gordon
Jun 23 '07 #4
see also:
http://www.embedded.com/shared/print...icleID=9900661
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 23 '07 #5
On Jun 23, 5:18 am, Flash Gordon <s...@flash-gordon.me.ukwrote:
Gene wrote, On 23/06/07 05:20:
Hello all. I do not have access to the ANSI standard doc. Perhaps

<snip>

If you go tohttp://clc-wiki.net/wiki/c_standardthere are links to
where you can obtain drafts of the various versions of the C standard
and information about the different types, including why I use the ISO
(or BSI) standard rather than the ANSI one.

Others have answered your main question correctly so I won't.
--
Flash Gordon
Thanks! This is very helpful, as are all the answers to the original
question.
Jun 24 '07 #6

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

Similar topics

4
by: j | last post by:
In a footnote in the c99 standard the following is labeled as undefined: a = i; And in the second clause of section 6.5 the following is stated: "Between the previous and next sequence...
4
by: Eric E | last post by:
Hi, I have a question about sequences. I need a field to have values with no holes in the sequence. However, the values do not need to be in order. My users will draw a number or numbers from...
3
by: kevin | last post by:
Is that even possible? I am creating a web service in .NET to expose some already created .NET programs to other groups. One group is writing the client in PERL, and thus wishes the wsdl schema...
7
by: Kenneth Brody | last post by:
(From something brought up on "Help with array/pointer segmentation fault needed" thread.) Is "?" a sequence point? Or, more directly, is the following defined? /* Will "ptr" be guaranteed...
2
by: Kai-Uwe Bux | last post by:
Please consider #include <iostream> int main ( void ) { int a = 0; a = ( (a = 5), 4 ); // (*) std::cout << a << '\n'; }
3
by: somenath | last post by:
Hi All, I have one question regarding the conditional operator. In the draft C99 standard it is mentioned that "1 The following are the sequence points described in 5.1.2.3: -- The call to a...
5
by: majestik666 | last post by:
Am not sure if it's been asked before (did a search but didn't come up with anything related...). I'm trying to write some code to "collapse" image sequences into a single item , i.e.:...
21
by: bilgekhan | last post by:
After doing a succcessful insert() or find() on a set<Tcontainer is it possible to get the item number of this item in the set? (ie. its zero-based sequence number (position/location/rank/index)...
5
by: =?ISO-8859-1?Q?Marcel_M=FCller?= | last post by:
Hi, I have a question about the execution sequence of the postfix increment operator with respect to a function call. void foo(int type, int*& data); int* sequence;
8
by: Jrdman | last post by:
what's a sequence point and how to know the position of sequence point in our source code?
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.