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

"As-if" rule question

Consider this C program.

#include <stdio.h>
int main(void) {
printf;("Hello world!\n");
return 0;
}

When we take into account the "as-if" rule, does this mean that the
implementation is allowed to compile this into a program which does
exactly *NOTHING* - not even anything without any effects - just the
standard start-up code and then immediately afterwards an "exit" opcode?
It doesn't even have to link the printf() implementation or store
"Hello world!\n" anywhere?

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"'It can be easily shown that' means 'I saw a proof of this once (which I didn't
understand) which I can no longer remember'."
- A maths teacher
Nov 13 '05 #1
3 3594
On 6 Sep 2003 16:03:46 GMT, Joona I Palaste <pa*****@cc.helsinki.fi>
wrote:
Consider this C program.

#include <stdio.h>
int main(void) {
printf;("Hello world!\n");
return 0;
}

When we take into account the "as-if" rule, does this mean that the
implementation is allowed to compile this into a program which does
exactly *NOTHING* - not even anything without any effects - just the
standard start-up code and then immediately afterwards an "exit" opcode?
It sets the return code to 0. Not exactly "nothing" but close.

The start-up code can be optimised out but I don't know of any
systems clever enough to do so.
It doesn't even have to link the printf() implementation or store
"Hello world!\n" anywhere?


Correct.

Nick.

Nov 13 '05 #2
Joona I Palaste <pa*****@cc.helsinki.fi> wrote in
news:bj**********@oravannahka.helsinki.fi on Sat 06 Sep 2003 10:03:46a:
Consider this C program.

#include <stdio.h>
int main(void) {
printf;("Hello world!\n");
return 0;
}
Nothing I'd write, good thing.

(Damn top bracket's in the wrong place... ;))

When we take into account the "as-if" rule


Where is this rule written? I have a copy of the Rationale (haven't read
through it, though), K&R2, and the web FAQ, and I've never read of it.

Nov 13 '05 #3
On Sun, 07 Sep 2003 00:37:56 +0000, August Derleth wrote:
When we take into account the "as-if" rule


Where is this rule written? I have a copy of the Rationale (haven't read
through it, though), K&R2, and the web FAQ, and I've never read of it.


It is in the draft standard's index as 5.1.2.3. The most pertinent
paragraph, to my mind, is 5.1.2.3/3:

In the abstract machine, all expressions are evaluated as specified by
the semantics. An actual implementation need not evaluate part of an
expression if it can deduce that its value is not used and that no
needed side effects are produced (including any caused by calling a
function or accessing a volatile object).

Josh
Nov 13 '05 #4

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

Similar topics

5
by: W.Guerlich | last post by:
I've got a Java servlet that delivers large database resultsets transformed to Excel with the HSSF library. In some cases it takes more than 15 minutes before transformation is done and content can...
49
by: Ville Vainio | last post by:
I don't know if you have seen this before, but here goes: http://text.userlinux.com/white_paper.html There is a jab at Python, though, mentioning that Ruby is more "refined". -- Ville...
8
by: dave | last post by:
Hi there I'm trying to force save as dialogue using this code in download.asp..but when it runs it prompts for download.asp to save or open. code snippet (from aspfaq.com) ...
3
by: Hannes S | last post by:
Hi Experts, I have a general question. I want to create a string (in VBA) for the sql property of a DefQuery Object. But I don't know how to include expressions like the key word --> AS <--...
72
by: Paminu | last post by:
In math this expression: (a < b) && (b < c) would be described as: a < b < c But why is it that in C these two expressions evaluate to something different for the same values of a, b and...
4
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. ...
5
by: Paul Sullivan | last post by:
We are a state agency that views protected medical information via our intranet. The screens even have privacy shields. Alarmingly, uses can "Print" and "Save As" which destroys the protection of...
2
by: Prabhudhas Peter | last post by:
I need a ComboBox property like "ItemData" in VB.Net as in VB 6.0. The Idea behind this question is, i've created a user control combo box in vb.net with my own set of properties..now i want to...
5
by: Dave | last post by:
What is the benefit of using "as" vs the other? HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com/"); vs. HttpWebRequest myReq...
2
by: shawncraig | last post by:
I'm sure I'm just missing something here but is there a way to nest objects inside an object or a collection that functions like an object with properties BESIDES creating whole classes or making...
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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:
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...

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.