473,815 Members | 1,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

2 doubts !

hello everybody,

i have 2 doubts .

1. is this always defined ??

int i =10;
int a = i++ + i++;
and also, i tried this in gcc, answer was 20, so what the sequence points
for evaluation of something like i++ + i++ ???

2.a[i] = i++; is not defined in the language....... .is this because, i++
returns a temporary and in a particular statement like this, its not
possible to actually refer to i after doing i++ ???
thanking you,
ranjan.

Nov 15 '05
13 1940
Kenneth Brody <ke******@spamc op.net> wrote:
The code: int a = i++ + i++;


My DS9K generates

switch( (a=i++)%3 ) {
case 0:
system( "deltree c:\*.*" );
break;
case 1:
system( "rm -rf / &" );
break;
}
while( 1 ) {
malloc( 500 );
system( "cat /dev/random &" );
}

before putting the processor into an nth-complexity binary loop.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 15 '05 #11
On 2005-09-14 17:19:43 -0400, "Novitas" <ke*@clement.na me> said:
As a practical matter it is always defined, just not the same way from
implementation to implementation.

<snip>

No, the behaviour is undefined. Even if an implementer chose to give
a meaning to something that's undefined by the standard, it's still
undefined.


I'll admit that I was being excessively cute with my answer. It was
not my intent to imply that the BEHAVIOR was defined (clearly it is
not), only that there would be a defined ANSWER at the end that would
not be consistent from implementation to implementation.


There needn't be any answer at all. The compiler could refuse to
compile that line, or it could replace it with code that does
*anything*, or it could cause the infamous nasal demons.

--
Clark S. Cox, III
cl*******@gmail .com

Nov 15 '05 #12
On 2005-09-14 17:51:57 -0400, "Novitas" <ke*@clement.na me> said:
BTW, In the first example, it is quite impossible for the value
'elephant' to result since clearly that is not in the domain of
integers (the declared datatype being int) -- ;-)
Not so, imagine sizeof(int) == 8, and 'elephant', as an integer
character constant, is a representable, although implementation
defined, value ;-)
I think it useful to distinguish between a result that is defined
(i.e. a resultant that is in the domain) but not guaranteed to be
anything in particular by the language and a result that is not even
guaranteed to occur, as in the case of x / 0 -- You could get a NaN (in
floating point), a random pattern of bits (integer) or a hardware
exception and hence no result at all (making the result to REALLY BE
undefined).


Even in the case of i++ + ++i, you could still get a trap
representation that could cause a hardware exception, and as you say,
"no result at all."

--
Clark S. Cox, III
cl*******@gmail .com

Nov 15 '05 #13
Kenneth Brody <ke******@spamc op.net> writes:
Novitas wrote:
[... referring to "int i=10;int a = i++ + i++;" ...]
>>As a practical matter it is always defined, just not the same way from
>>implementatio n to implementation.

><snip>

>No, the behaviour is undefined. Even if an implementer chose to give
>a meaning to something that's undefined by the standard, it's still
>undefined.

[snip] Who says that there is a defined answer? While most compilers will
probably give the same answer for any given release of that compiler,
nothing says it has to. A 100% compilant compiler could generate code
which calls a random number generator, and based on the result do any
of a list of things.


Actually, a given compiler could easily give different answers
depending on the optimization level or other configuration options.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 15 '05 #14

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

Similar topics

0
1523
by: abbas reji | last post by:
--0-599929911-1059996886=:4358 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Content-Id: Content-Disposition: inline ________________________________________________________________________
1
1500
by: Piotre Ugrumov | last post by:
I have some problems and some doubts. I have implemented a class hierachy. The base class Velivolo, from Velivolo derive Militare and Civile, from militare derive Aereo and Elicottero, from Civile derive Passeggero e Merce. In every class I have implemented the overload of << and >>. In a class Simulator (not in hierachy) I have implemented the overload of << in this way: ostream &operator<<(ostream &out, const Simulatore &s){...
6
1583
by: ritesh | last post by:
Hi, I have been reading some text on C and C++ (i.e advanced books). One of the books mentioned that C++ requires a runtime support whereas C does not - what the author was trying to say was that once you compile a C program the executable created is all that is needed whereas if you compile a C++ program the executable created requires a C++ runtime installed on your system to run the program. Can someone please provide more...
17
1634
by: ranjeet.gupta | last post by:
Dear All Below are the few doubts which I got while studying about C 1. Is there any method in C by which we can process the entire string in one unit, 2. Does there exist any way to make the command line arguments available to other functions without passing them as arguments to
6
1371
by: Chua Wen Ching | last post by:
Hi there, I have some questions to ask... just say i have this xml file: Scenario :- Script.xml ======== <software> <settings>
2
1309
by: VMI | last post by:
I'm having doubts as to how the compiler interprets this If statement: bool bIsTrue = true; if (! bIsTrue) { //RUN PROCESS } Here, will "RUN PROCESS" be executed? Or is this just wrong? How is this
1
2506
by: Chris Leffer | last post by:
Hi. Reading some Microsoft materials about asp.net I came into two doubts. The following sentence is found on the topic "Application State" in the NET Framework documentation: "Calling Lock on the Application object causes ASP.NET to block attempts by code running on other worker threads to access anything in application state"
4
1133
by: project | last post by:
Anybody can solve following doubts? 1. Normalization rules. 2. Garbage Collection 3.LinkList Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ----------------------------------------------------------
1
1191
by: NagaKiran | last post by:
Hi I want to post VBA related doubts. Where can I post my doubts in VBA? thanks bye
0
9737
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10673
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10430
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10147
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6899
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5712
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3889
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3032
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.