in reply to Beautiful code I wrote ;-)

Doesn't C have an obligatory warning for this?

Replies are listed 'Best First'.
Re^2: Beautiful code I wrote ;-)
by massa (Hermit) on Jul 15, 2008 at 15:01 UTC
    NO.
    even with -Wall -pedantic, gcc does not complain. And there would be no reason to. 1 << a >> 1 is very much a well-formed C expresion, meaning "shift left the int with value '1' by 'a' bits; shift right the result by one bit".
    []s, HTH, Massa

      Gcc indeed doesn't seem to complain, however, there was a reason why I remembered there was a warning, and it's a different compiler. Borland C 3.1 has such a warning.

      Update: I recreated a variant of the screenshot I've linked to and made a text export. Non-ascii characters are wrong so the image I linked to is still better, but I copy the text version here in case you can't view the image and because it's not hosted on perlmonks.

      = File Edit Search Run Compile Debug Project Options Wind +ow Help +--------------------------------- \TEMP\A.C ------------------------- +---2-----+ |#include <stdio.h> + | |int +-[_]---------- About ----- +---------+ |main(void) { | + | | return(1 << 5 >> 1); | Borland C++ + | |} | + | | | Version 3.1 + | | | + | | | Copyright (c) 1990, 19 +92 by | | | + | | | Borland International, + Inc. | | | + | | | OK _ + | | | ________ + | | +-------------------------- +---------+ +------- 4:21 -------------------------------------------------------- +---------+ +-[_]------------------------------ Message -------------------------- +---3-[o]-+ | Compiling ..\TEMP\A.C: + ^ |*Warning ..\TEMP\A.C 4: Ambiguous operators need parentheses + _ | Linking A.EXE: + _ | + _ | + v +-<___________________________________________________________________ +_______>-+ F1 Help | Accept the settings in this dialog box