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

what is wrong with this code

I read it somewhere on net but dont know the answers..

What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;

Thanks,
Cric

Oct 14 '05 #1
6 4003

fr*******@yahoo.com wrote:
I read it somewhere on net but dont know the answers..

What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;


value could be a dangling reference.

Seriously, you have to provide more context.

Oct 14 '05 #2

<fr*******@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I read it somewhere on net but dont know the answers..

What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;

You're attempting you use value without properly initializing it.
This causes undefined behaviour.

Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>
Oct 14 '05 #3
fr*******@yahoo.com wrote:
I read it somewhere on net but dont know the answers..

What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;

Thanks,
Cric


There's nothing potentially wrong with it. Some may tell you that the
behavior is undefined according to 4.1 of the Standard. But 4.1 applies
only to lvalue to rvalue conversions of which none are present in this
example. Also, the C language Standard is even more clear than the C++
standard, but both agree that value's initial value is indeterminate,
not undefined.

So in this example, value's value is indeterminate before the bitwise
and, and its value is unchanged afterwards - assuming ints are
four-byte in size, of course.

Greg

Oct 14 '05 #4
In message <11**********************@g43g2000cwa.googlegroups .com>, Greg
<gr****@pacbell.net> writes
fr*******@yahoo.com wrote:
I read it somewhere on net but dont know the answers..

What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;

Thanks,
Cric


There's nothing potentially wrong with it. Some may tell you that the
behavior is undefined according to 4.1 of the Standard. But 4.1 applies
only to lvalue to rvalue conversions of which none are present in this
example. Also, the C language Standard is even more clear than the C++
standard, but both agree that value's initial value is indeterminate,
not undefined.

So in this example, value's value is indeterminate before the bitwise
and, and its value is unchanged afterwards - assuming ints are
four-byte in size, of course.

ITYM "assuming longs are two-byte in size".

Which they aren't, of course ;-)

--
Richard Herring
Oct 14 '05 #5

"Greg" <gr****@pacbell.net> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
fr*******@yahoo.com wrote:
I read it somewhere on net but dont know the answers..

What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;

Thanks,
Cric


There's nothing potentially wrong with it. Some may tell you that the
behavior is undefined according to 4.1 of the Standard. But 4.1 applies
only to lvalue to rvalue conversions of which none are present in this
example. Also, the C language Standard is even more clear than the C++
standard, but both agree that value's initial value is indeterminate,
not undefined.


Isn't the line:
value &= 0xFFFF;

an lvalue to rvalue conversion in the same sense as

int i = i;

?

So would this not become undefined behaviour as per 4.1/1?

Regards,
Sumit.
--
Sumit Rajan <su*********@gmail.com>
Oct 14 '05 #6
On 14 Oct 2005 02:22:55 -0700, "Greg" <gr****@pacbell.net> wrote in
comp.lang.c++:
fr*******@yahoo.com wrote:
I read it somewhere on net but dont know the answers..

What's potentially wrong with the following code?
long value;
//some stuff
value &= 0xFFFF;

Thanks,
Cric
There's nothing potentially wrong with it. Some may tell you that the
behavior is undefined according to 4.1 of the Standard. But 4.1 applies
only to lvalue to rvalue conversions of which none are present in this
example. Also, the C language Standard is even more clear than the C++
standard, but both agree that value's initial value is indeterminate,
not undefined.


You are quite incorrect. To perform the '&=' operation, lvalue to
rvalue conversion must be performed. Since this is use of an
indeterminate value, the value is indeed undefined.
So in this example, value's value is indeterminate before the bitwise
and, and its value is unchanged afterwards - assuming ints are
four-byte in size, of course.

Greg


--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Oct 15 '05 #7

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

Similar topics

125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
72
by: E. Robert Tisdale | last post by:
What makes a good C/C++ programmer? Would you be surprised if I told you that it has almost nothing to do with your knowledge of C or C++? There isn't much difference in productivity, for...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
51
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. Jason
1
by: GS | last post by:
I got a combobox box that I load at load time. the Item and vales ended up in reverse order of each other, what went wrong? the database table has the following row code value ebay ...
98
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
9
by: Pyenos | last post by:
import cPickle, shelve could someone tell me what things are wrong with my code? class progress: PROGRESS_TABLE_ACTIONS= DEFAULT_PROGRESS_DATA_FILE="progress_data" PROGRESS_OUTCOMES=
20
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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...

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.