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

code to transform assignment statement

In preparing a C++ source file, a programmer has wrtten the assignment statement in long-hand form as shown

a=a+12;
rather than in its short-hand form
a+=12
Develop a class which reads the source file and provides the necessary operations for replacing the assignment statements as listed below

a=a+...; by a+=..;
a=a-...; by a-=..;
a=a*...; by a*=..;
a=a/...; by a/=..;
May 1 '07 #1
2 1312
Ganon11
3,652 Expert 2GB
OK...very interesting...so what?
May 1 '07 #2
JosAH
11,448 Expert 8TB
OK...very interesting...so what?
I'd say: extremely interesting; totally useless but extremely interesting nevertheless.
First you have to preprocess the translation unit; next you have to parse the whole
thing down to the expression level; if you find an assignment where the lvalue
equals the left operand of the rvalue on the right of the compound assignment
operator apply the transformation.

Things become interesting when the lvalue and the left hand operand are aliases
of each other:
Expand|Select|Wrap|Line Numbers
  1. int a= 42;
  2. int* pa= &a;
  3. a= *pa+1;
and what about modified aliases?
Expand|Select|Wrap|Line Numbers
  1. int a= 42;
  2. int* pa= &a;
  3. a= *pa+++1;
Extremely interesting; useless and undoable; but extremely interesting ;-)

kind regards,

Jos
May 1 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

47
by: fb | last post by:
Hi Everyone. Thanks for the help with the qudratic equation problem...I didn't think about actually doing the math...whoops. Anyway... I'm having some trouble getting the following program to...
10
by: yanyo | last post by:
hi, im starting out in C prog and im stuck in this code, its supposed to calculate this inputs and give out the total expense of gas... #include <stdio.h> int main() { int miles_per_gallon,...
5
by: Brad Williams | last post by:
I'm trying to get clearer on limitations of assignment/modifications within a foreach. Why does the following gives a compilation error if MyType is a struct, but it does not if MyType is a class?...
35
by: nagy | last post by:
I do the following. First create lists x,y,z. Then add an element to x using the augumented assignment operator. This causes all the other lists to be changed also. But if I use the assignment...
6
by: Vijai Kalyan | last post by:
Hello, I am trying to use std::transform to take in a collection of strings, transform them and insert the result into an output container. So, I wrote something like this: std::wstring...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
19
by: Pavan | last post by:
Hi, I want to know if there is any software for measuring lines of code of my c++ application. I found out a tool, sloccount, but it gives only physical lines of code. I found out one more...
19
by: Taras_96 | last post by:
Hi all, A poster at http://bytes.com/forum/thread60652.html implies that using strtoupper in transform doesn't work because ctype.h may define strtoupper as a macro: "The problem is that most...
13
by: Ramon F Herrera | last post by:
I am writing a program that generates source code. See a snippet below. My question is about the use of that growing 'code' variable. Is it efficient? Is is recommended for this case? The code...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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
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,...

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.