[chbot] Pop quiz C

Charles Manning cdhmanning at gmail.com
Wed Apr 26 00:00:26 BST 2017


It depends.... the ultimate weasel answer :-).

I get a compilation error because I always compile with -Wall -Werror.
SInce everyone should be doing that (my decree) that is the ultimate answer.


gcc bigshift.c -o bigshift -Wall -Werror
bigshift.c: In function ‘main’:
bigshift.c:5:29: error: left shift count >= width of type
[-Werror=shift-count-overflow]
   printf("%d\n", 0xFFFFFFFF << 34);
                             ^
cc1: all warnings being treated as errors


On Wed, Apr 26, 2017 at 10:52 AM, Mark Atherton <markaren1 at xtra.co.nz>
wrote:

> Doesn't it depend on what 'a' is declared as, and the language ?
>
> Assuming C, and if 'a' was a U32, and 0xFFFFFFFF was 0xFFFFFFFFL, and 34
> was 34L, then possibly the answer might, perhaps, possibly be 0.
>
> having said that, given the context of the question and the person asking
> the question, I smell an odorous rodent :)
>
> -Mark
>
> http://www.c4learn.com/c-programming/c-bitwise-left-shift-operator/ ties
> up with my understanding, but again I may need more anti-paranoia
> medication...
>
>
> On 26 April 2017 at 10:04 hamster <hamster at snap.net.nz> wrote:
>
> Sorry - no chocolate fish this time
>
> What is the value of a?
>
>   a = 0xFFFFFFFF << 34;
>
> Have you checked your answer?
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
>
>
>
>
> _______________________________________________
> Chchrobotics mailing list Chchrobotics at lists.linuxnut.co.nz
> http://lists.ourshack.com/mailman/listinfo/chchrobotics
> Mail Archives: http://lists.ourshack.com/pipermail/chchrobotics/
> Meetings usually 3rd Monday each month. See http://kiwibots.org for
> venue, directions and dates.
> When replying, please edit your Subject line to reflect new subjects.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ourshack.com/pipermail/chchrobotics/attachments/20170426/afa5c56d/attachment.html>


More information about the Chchrobotics mailing list