473,949 Members | 1,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

complier problem

Hi

My question is : Would the expression *p++=c be disallowed by the
complier.
The answer given in the book is: No.Because here even though the vlue
of p is acced twice it is used to modify two different objects p and
*p.
so can anyone explain this answer to me detail

Jul 28 '06
11 2658
>Chris Torek wrote:
>>[the compiler can produce varying machine code for the C source:]
save = p++;
In article <r9************ *************** ***@comcast.com >,
Ark <ak*****@macroe xpressions.comw rote:
>Looks like a storm in a teacup. ['save' doesn't have to exist at all,
depending on the instruction set,
The intent of this later example -- which I admit is not clear if
you follow the whole thread and think that it is *not* a separate
example -- is that the "save = p++;" is a complete line of C source
code. Hence "save" *does* exist, right there in the source code. :-)
>and *p++=c; may execute in a single instruction]
On some architectures (try it on a SPARC or MIPS!); but this is a
different line of source code anyway. :-) And of course, while a
number of architectures have a single instruction that implements
"*p++ = expr" and "*--p = expr", many of those do not have a single
instruction that implements "*++p = expr" or "*p-- = expr". (But
some do.)
>p++ has a value (old p) and a side effect (p = old p + 1).
*p++ dereferences the value of p++ (old p).
(Correct -- but can you say that in no fewer than 1000 words? :-) )
>I'd care about implementation only when shopping for a compiler (or
squeezing out that last optimization)
Indeed, this is an appropriate attitude.
--
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.
Jul 29 '06 #11
"neha" <ne*********@gm ail.comwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.com.. .
Hi

My question is : Would the expression *p++=c be disallowed by the
complier.
The answer given in the book is: No.Because here even though the vlue
of p is acced twice it is used to modify two different objects p and
*p.
so can anyone explain this answer to me detail
Your question is similar to a FAQ, did you read it before posting?:

----------------------------------------------------
4.3: Does *p++ increment p, or what it points to?

A: Postfix ++ essentially has higher precedence than the prefix
unary operators. Therefore, *p++ is equivalent to *(p++); it
increments p, and returns the value which p pointed to before p
was incremented. To increment the value pointed to by p, use
(*p)++ (or perhaps ++*p, if the order of the side effect doesn't
matter).

References: K&R1 Sec. 5.1 p. 91; K&R2 Sec. 5.1 p. 95; ISO
Sec. 6.3.2, Sec. 6.3.3; H&S Sec. 7.4.4 pp. 192-3, Sec. 7.5 p.
193, Secs. 7.5.7,7.5.8 pp. 199-200.
----------------------------------------------------
A side point:
I would never rely on the compiler to reject a nonsense code fragment.
There are some types of problems that the compiler MUST issue a diagnostic
message for, but there are other things that are totally wrong but which the
compiler does not have to diagnose.
Aug 2 '06 #12

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

Similar topics

0
1432
by: Francisco J. Reyes | last post by:
I get an Internal complier error when compiling C# windows project that uses a custom Class add as reference to the project. The problem appears to be related to the ENUM type used in the class controland where the windows project attempts to call the custom class property set\get a specific value using enum values from the custom class. Thanks in advance.
3
1688
by: Ygn | last post by:
#include <stdio.h> #include <winsock2.h> #include <windows.h> #include <process.h> #include <string.h> #include <winbase.h> #include <sys/socket.h> I would like to do compiling this header. When I try with my VC ++ I got error. So what the name of complier and where can I get it.
5
2759
by: Seven Kast USA | last post by:
Hi pelase explain me complier design of c and i need a small example complier design all phases in c programming . by KAST
2
4181
by: qbin_wang | last post by:
Hi: now i want to download a free c complier which can be used in windows system.and i see many posts in the comp.lang.c,but i don't find the answer.who can tell me the true and correct website that can download the c complier or tell me the c complier's name. thanks a lot.
2
3152
by: Ali Alsaffar | last post by:
Hi there, - I updated my windows XP professional with all critical updates available at windowsupdate.com - I updated Microsoft .NET Framework 1.1.4322 from thier also - I installed Visual Basic 6 Enterprise Edition - Then I also installed Visual Basic .NET 2003 Professional Edition - I created a new project in Visual Basic 6 successfully - Here is the problem: I failed to create a new Visual Basic project in Visual Basic .NET 2002 I got...
8
7108
by: shannon | last post by:
Hi there, Does anyone know if you can download a free javascript complier from the net. I need to check my code for a project. Thanks Shannon.
11
2297
by: jryden | last post by:
I wrote the following code into a console program in Visual C++6. If you build a release build and select custom optimizations and select 'general optimizations' as the only optimization then you will end up with incorrect results. Every line seems to be important, even the unrelated bits. Any one have the time or inclination to try this out for themselves and try to explain it? #include "stdafx.h" #include <string>
1
2535
by: tccode97 | last post by:
Hi, I need an urgent help. I am developing a socket application in VC++ that uses asynchronous connnection. After doing search on google, I found the following link http://msdn2.microsoft.com/en-us/library/system.net.sockets.udpclient...
16
10127
by: sriever4u | last post by:
I am new to ARM linux, i am working on AT91RM9200 board and using ARM linuc C complier.. i want to know how to produce nanosecond delay using software...
0
10170
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
9989
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11591
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
11185
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
11358
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
7435
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
6343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3552
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.