473,738 Members | 11,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need some explanation

hello,
1) First how following program get executed i mean how output is
printed and also why following program gives different output in Turbo
C++ compiler and Visual c++ 6 compiler?
void main()
{
int val=5;
printf("%d %d %d %d",val,--val,++val,val--);
}
under turbo compiler its giving
4 4 5 5
and under visual c++ its
5 5 6 5

2) How to evaluate following statement
int val =5;
val =- --val - val-- - --val;

Nov 15 '05
70 2816
Chris Hills wrote:
In article <42************ ***@yahoo.com>, CBFalconer
<cb********@yah oo.com> writes

Tobias is missing the point that the subject of c.l.c is _portable_
C code, as defined by the standards from K&R through C89, C90, C95,
and C99. If you have to specify the implementation, you are
off-topic here.


Does it say that in the charter for this NG?


Yes.

And before you ask, I have it locked away in a cupboard here at MI5
headquarters, where only authorised personnel are able to read it.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #41
In article <db**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>, Richard
Heathfield <in*****@addres s.co.uk.invalid > writes

Far too much is written on the subject of void main. This is really simple
to get right - even the most trivial reading of the Standard shows that an
int return type is the natural choice for C programs that are intended to
be portable, so why not just use int?


I agree. The only time you would not use int is in a free-standing
system where there is nothing to return to. Otherwise there is no
justification for not doing it.
--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #42
In article <db**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>, Richard
Heathfield <in*****@addres s.co.uk.invalid > writes
Chris Hills wrote:
In article <42************ ***@yahoo.com>, CBFalconer
<cb********@yah oo.com> writes

Tobias is missing the point that the subject of c.l.c is _portable_
C code, as defined by the standards from K&R through C89, C90, C95,
and C99. If you have to specify the implementation, you are
off-topic here.

Does it say that in the charter for this NG?


Yes.


Then please post it. Seriously I should be interested to see it.
And before you ask, I have it locked away in a cupboard here at MI5
headquarters , where only authorised personnel are able to read it.


The only MI5 that I am aware of is a Graphics company Mike India 5 Ltd
(co number. 02907648 ) by Junction 2 of the M4.
(used to be www.mi-5.co.uk but it is a blank page now)

Though you do work for a highly connected organisation :-)
I will ask for the charter at next time I am passing the office

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #43
Chris Hills wrote:

In article <db**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>,
Richard Heathfield <in*****@addres s.co.uk.invalid > writes
Chris Hills wrote:
the charter for this NG?
And before you ask, I have it locked away in a cupboard here at MI5
headquarters , where only authorised personnel are able to read it.


The only MI5 that I am aware of is a Graphics company Mike India 5 Ltd


MI5 is his cover. You can easily deduce from his activities
that he really works for MI6.

http://www.mjnewton.demon.co.uk/bond/jbssfaq.htm

--
pete
Nov 15 '05 #44
pete wrote:
Chris Hills wrote:
In article <db**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>,
Richard Heathfield <in*****@addres s.co.uk.invalid > writes
Chris Hills wrote:
the charter for this NG?
And before you ask, I have it locked away in a cupboard here at MI5
headquarters , where only authorised personnel are able to read it.


The only MI5 that I am aware of is a Graphics company Mike India 5 Ltd

MI5 is his cover. You can easily deduce from his activities
that he really works for MI6.

http://www.mjnewton.demon.co.uk/bond/jbssfaq.htm


At MI6 there is Richard Bond, 006-7/8. He is under such deep cover that
nobody knows how to fix his Martini. He drives a really cool 1992 Mazda
Miada. Is that our man? :-)

Welcome back Richard.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 15 '05 #45
Chris Hills <ch***@phaedsys .org> writes:
In article <db**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>, Richard
Heathfield <in*****@addres s.co.uk.invalid > writes

Far too much is written on the subject of void main. This is really simple
to get right - even the most trivial reading of the Standard shows that an
int return type is the natural choice for C programs that are intended to
be portable, so why not just use int?


I agree. The only time you would not use int is in a free-standing
system where there is nothing to return to. Otherwise there is no
justification for not doing it.


Just out of curiosity, are there any freestanding implementations that
accept
void main(void) { }
that *don't* accept
int main(void) { return 0; }
(with the same effect)? If not, there's even less reason to use void
main() -- though I suppose if you're certain your code will only ever
be compiled on a system that accepts void main(), there's no much
reason not to use it.

--
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 #46
In article <ln************ @nuthaus.mib.or g>, Keith Thompson <kst-
u@mib.org> writes
Chris Hills <ch***@phaedsys .org> writes:
In article <db**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>, Richard
Heathfield <in*****@addres s.co.uk.invalid > writes

Far too much is written on the subject of void main. This is really simple
to get right - even the most trivial reading of the Standard shows that an
int return type is the natural choice for C programs that are intended to
be portable, so why not just use int?


I agree. The only time you would not use int is in a free-standing
system where there is nothing to return to. Otherwise there is no
justification for not doing it.


Just out of curiosity, are there any freestanding implementations that
accept
void main(void) { }
that *don't* accept
int main(void) { return 0; }
(with the same effect)? If not, there's even less reason to use void
main() -- though I suppose if you're certain your code will only ever
be compiled on a system that accepts void main(), there's no much
reason not to use it.


Good point. I am not sure if they would actually accept it. Never tried
it.

However it is incorrect as it implies main can return which it can't.
In many situations a return from main is fatal.

In a free-standing system it would be as incorrect to use int main as it
is to use void main in a hosted environment. Though there is less harm
in using void main in a hosted environment.

The int return in a hosted system is stylistic. There is often nothing
returned so having a void makes no difference. If you do need to return
something then you have to put it in.

In a free-standing system having a return the implication is that the
program could terminate. This is not something you want to have even as
a fleeting thought. Many free standing systems are embedded systems and
safety critical.

Personally I would never write a hosted application without the int
return but I would never put a return type other than void on a free-
standing system.

--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ ch***@phaedsys. org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

Nov 15 '05 #47
In article <86************ **@phaedsys.dem on.co.uk>,
Chris Hills <ch***@phaedsys .demon.co.uk> wrote:
In a free-standing system it would be as incorrect to use int main as it
is to use void main in a hosted environment. In a free-standing system having a return the implication is that the
program could terminate. This is not something you want to have even as
a fleeting thought. Many free standing systems are embedded systems and
safety critical.


What you are indicating is that ANSI/ISO should -define- main() for
freestanding implementations as an infinite loop, to prevent
the -possibility- that it might exit -- because the application just
might happen to be safety critical. And that the default signal
handling should be "re-invoke the program entry point" instead of
"terminate" .
What was the name of that new language element again?

exit_from_embed ded_program_Yes _Yes_Yes_I_have _thought_about_ the_possible_im plact_on_safety _and_I_still_wa nt_to_do_it_and _I_will_take_pe rsonal_responsi bility (
struct *Here_are_my_la wyers_contact_d etails_so_I_can _be_personally_ sued_if_I_was_w rong_and_should _not_have_allow ed_the_program_ to_exit )
--
The rule of thumb for speed is:

1. If it doesn't work then speed doesn't matter. -- Christian Bau
Nov 15 '05 #48
In article <86************ **@phaedsys.dem on.co.uk>
Chris Hills <ch***@phaedsys .demon.co.uk> wrote:
In a free-standing system having a return the implication is that the
program could terminate. ...


Many freestanding system programs *do* terminate, and correctly so.
(Many others do not, also correctly so.) I would argue that this is
irrelevant:

A hosted C system (that conforms to either C89 or C99) is *guaranteed*
to accept, and do something at least marginally useful with, an
"int main" function with a return value that is one of the three
standard values (0, EXIT_SUCCESS, and EXIT_FAILURE).

A freestanding C system need not even *use* a function named
main().

My personal preference (though I admit I do not always get my way
:-) ) is to write hosted applications using "int main" and freestanding
applications using *no* function named "main" at all. When it is
done this way, I find there is minimal confusion and maximal
bug-reduction. (I write a lot of code that runs in one or the
other situation, or sometimes even both. When the code needs to
run on both freestanding and hosted systems, the "int main()" piece
is usually quite short, as is the freestanding system's "main-like"
entry point: both set up the environment needed to call the "real"
program start. In most cases, the unused stub -- the function
named main() in the freestanding code, which is unused there because
the program starts in start(); and start() in the hosted code,
which is unused there because the program starts in main() -- can
be left in, although for memory-footprint sake, one may often want
to omit main() in the embedded/freestanding version.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 15 '05 #49
Chris Hills wrote:
In article <db**********@n wrdmz02.dmz.ncs .ea.ibs-infra.bt.com>, Richard
Heathfield <in*****@addres s.co.uk.invalid > writes
Chris Hills wrote:
In article <42************ ***@yahoo.com>, CBFalconer writes
If you have to specify the implementation, you are
off-topic here.
Does it say that in the charter for this NG?
Yes.


Then please post it. Seriously I should be interested to see it.


But hang on, I covered that...
And before you ask, I have it locked away in a cupboard here at MI5
headquarter s, where only authorised personnel are able to read it.


The only MI5 that I am aware of is a Graphics company Mike India 5 Ltd
(co number. 02907648 ) by Junction 2 of the M4.
(used to be www.mi-5.co.uk but it is a blank page now)


Yes, very blank; we're not particularly tolerant of competitors.

Though you do work for a highly connected organisation :-)
I will ask for the charter at next time I am passing the office


Excellent. You will be expected. Please make sure your affairs are in order
before calling.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
Nov 15 '05 #50

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

Similar topics

2
1851
by: Carolyn Gill | last post by:
I have already created an asp login/database for a learning/quiz section on a small site. There will be multiple quizzes through the site and what I need now would be help: tutorials or advice that a complete novice can understand/follow to create the following: A small simple quiz--for now each has just one question with 5 multi-choice buttons. On submit should send the answer to A) a database (using access for now) to track scoring...
2
2127
by: Susan Bricker | last post by:
Greetings. Before I begin, I have been stuck on this problem for about a 5 days, now. I have tried and just seem to be not getting anywhere. I know that the explanation is lengthy, but I am a relative newcomer to Access and need to be methodical until it become more familiar. Thanks in advance for your help. I have a form with a subform that has a subform. form: frmEvents subform: sfrmTrialInfo (controlname = )
17
2675
by: Hazz | last post by:
In this sample code of ownerdraw drawmode, why does the '(ComboBox) sender' line of code need to be there in this event handler? Isn't cboFont passed via the managed heap, not the stack, into this cboFont_DrawItem event handler? Why does it need to be cast? -hazz ,................. cboFont.Items.AddRange(FontFamily.Families); } private void cboFont_DrawItem(object sender,
4
10146
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all the validators. The user enters the data, presses OK. My OK button is dynamically generated as well, with some code-behind logic in
18
1753
by: Susan Rice | last post by:
I'm comparing characters via return(str1 - str2); and I'm having problems with 8-bit characters being treated as signed instead of unsigned integers. The disassembly is using movsx eax,byte ptr to load my character in to EAX register. I need it to use movzx.
12
2116
by: jacob navia | last post by:
Hi I am writing this tutorial stuff again in the holidays and I came across this problem: The "width" field in printf is a minimum width. Printf will not truncate a field. for instance: #include <stdio.h> int main(void) {
4
1536
by: dismantle | last post by:
Hi all, this is my 3rd week in studying VB codes and i came across with this codes from a online tutorial about classes. Public Function MiddleInitial() As String MiddleInitial = Left$(middleNameValue, 1) End Function Public Function MiddleInitial(ByVal period As Boolean) As String MiddleInitial = Left$(middleNameValue, 1) & "."
4
1893
by: adam_kroger | last post by:
BRIEF EXPLANATION: I have 6 TextBoxes named LIS1, LIS2, LIS3, ... LIS6. I want to be able to reference them using a For/Next loop and either read ot write to them. In VBA I would use something like this: for i = 1 to 6 me.controls("LIS" & i).Value = "" next i Nedless to say, the Controls("LIS" & i).text doesn't work...
1
2933
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified CGI application misbehaved by not returning a complete set of HTTP headers. The scripts are very long but here are the opening statements: The One that works .... #!C:\Perl\bin\perl.exe # openresolver.cgi # # OpenResolver - a CGI script for...
1
2099
by: javabeginner123 | last post by:
i have a java prob, and i have to solve it fast, but i'm just getting to know it, so plz help me solve it with full code completed, thanks so much. the prob is to create a monter fight and there is the description: The monsters are of a very strange kind, called "Bigmon". They have some basic characteristics, like attack and defense power, life points, a name, and a bonus factor that is used in special occasions. In this initial phase of the...
0
8969
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
9476
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...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
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
9208
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
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6751
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
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();...
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.