Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Why does the value get discarded in this case?

Reply
Thread Tools

Why does the value get discarded in this case?

 
 
Chris Dollin
Guest
Posts: n/a
 
      06-07-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> On 6 Jun, 14:38, Chris Dollin <(E-Mail Removed)> wrote:
> [snip]
>>... giggling like an insane ferret on nitrous oxide.

>
> What a charming image - may I reuse it, please?


Certainly. No attribution required (but appreciated if present).

--
"It was the first really clever thing the King had said that day."
/Alice in Wonderland/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      06-07-2007
Keith Thompson wrote:

> Chris Dollin <(E-Mail Removed)> writes:
>> Chad wrote:
>>> int main(void)
>>> {
>>> int x = 256;
>>> x>>8;
>>>
>>> printf("The value is: %d\n", x);
>>> return 0;
>>> }
>>>
>>> I get:
>>>
>>> [cdalten@localhost ~]$ gcc -g -Wall seq.c -o seq
>>> seq.c: In function 'main':
>>> seq.c:6: warning: statement with no effect

>>
>> The shift operation `x >> 8` takes the value of `x`,
>> shifts it 8 places to the right, and throws the
>> result away.

> [...]
>
> Um, that's not quite the way I'd put it.
>
> The expression x>>8 yields the value of x right-shifted by 8 bits.
> Throwing away the result isn't a feature of the ">>" operator; the
> result is thrown away because you (the OP) asked for it to be thrown
> away, by using the expression as a statement (by adding the ';').


Ooof. You're quite right, Keith; I was sloppy. Thanks for the catch.

--
"Never ask that question!" Ambassador Kosh, /Babylon 5/

Hewlett-Packard Limited registered office: Cain Road, Bracknell,
registered no: 690597 England Berks RG12 1HN

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Cisco VPN client, packets beeing discarded and bypassed seansan Cisco 3 09-24-2006 10:50 AM
Fraudsters stealing personal details from discarded computers tedrichardson9925@sbcglobal.net Computer Information 2 08-21-2006 09:32 PM
discarded iterator.next() at interactive global scope doesn't bump interator?? Bengt Richter Python 2 09-04-2005 12:17 PM
Linker Message: "discarded section" Hartmut Sbosny C++ 2 05-29-2005 12:20 AM



Advertisments