04-29-2011
I answered your question previously:
- the value at the memory location gets changed.
- when the compiler sees the variable "i", it replaces it directly by "10" (it's OK to do so, since it is a const, it is not supposed to change).
You found a good example to illustrate this undefined behavior.
Cheers, Loïc
This User Gave Thanks to Loic Domaigne For This Post:
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Hi,
I have a while read loop that reads files in a directory and process. The files have spaces in between, so I have the IFS=\n to to read the whole line as one file name.
The read works fine but I have a problem with another variable that I set in the beginning of the script. The variable... (1 Reply)
Discussion started by: pvar
1 Replies
2. Shell Programming and Scripting
I have a variable:
$FILENAME = /XXXX/XXXX/XXXX/file.dat
I want to set another variable that will give me this:
$FILENAME2=filea.dat
So basically i'm chopping up variable $FILENAME.
Not sure cut will do this as i'm looking at different directories so the characther length may be... (2 Replies)
Discussion started by: Pablo_beezo
2 Replies
3. Programming
Is it permitted to type-cast a member variable passed in as a parameter in a member const method ..
I am doing something like :
in a
return-type method () const {
variable other = long(member variable)
}
this other assigned variable is not updating and I wonder if type-casting in such... (1 Reply)
Discussion started by: shriyer123
1 Replies
4. Programming
See code below. It appears that i and j inhabit the same address yet hold different values. Can anyone shed light on this?
int main() {
const int i= 3;
int* j = const_cast<int*>(&i);
*j = 5;
cout << j << endl << &i << endl;
cout << *j << endl << i;
} (4 Replies)
Discussion started by: StuartH
4 Replies
5. Programming
Hi,
Can any one tell me why my following program is crashing?
#include <iostream>
using namespace std;
class CA {
public:
const static int i;
};
const int CA::i = 10;
int main() {
int* pi = const_cast<int*>(&CA::i);
*pi = 9;
cout << CA::i << endl;
} (6 Replies)
Discussion started by: royalibrahim
6 Replies
6. Shell Programming and Scripting
Hi All please help if possible. I am a Unix novice. I have a similar question to the one posted by yonderboy at about a year ago. However his solution does not work for me.
The pseudo code for my problem is as follows:
for fund in 1 2 3 4
if (FTP is successfully) then
FILE_SENT_fund... (2 Replies)
Discussion started by: Seether
2 Replies
7. Shell Programming and Scripting
Dear all,
I have kind of used both the awk/sed command and found them really useful.
But at the necessity I am having right now, I need help.
Actually, I would like to do the following in file script.sh
PATH535="/eos/uscms/store/user/pooja04//analysis2012/535/mc/summer12/002/tt/"
... (2 Replies)
Discussion started by: emily
2 Replies
8. UNIX for Dummies Questions & Answers
Hi I am new to scripting and have a function in my .sh script file that outputs a html radio button form
weather_forecast_config()
{
echo ""
echo "<html><head><title>Welcome</title></head>"
echo "<body>"
echo "<h2>Weather Forecast - Change City</h2>"
echo "<form name="input"... (5 Replies)
Discussion started by: scriptnewbie
5 Replies
9. UNIX for Dummies Questions & Answers
Blank Blank Blank (11 Replies)
Discussion started by: pvibien
11 Replies
10. Shell Programming and Scripting
Hi Forum.
I have the following challenge at work that I need to write a script for.
I have a file abc.txt with the following contents:
4560123456
4570987654
4580654321
I want to be able to search/replace in abc.txt - the first 4 characters anything starting with 4560 to 7777; 4570... (3 Replies)
Discussion started by: pchang
3 Replies