This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: preprocessing directive with no new-line character


On 07/18/2017 06:33 PM, Jonathan Wakely wrote:
On 18 July 2017 at 21:46, Dennis Clarke wrote:
Fascinating. I never would have thought that a zero line length file
would be accepted as valid. However gcc ( older rev 4.9.2 ) will
accept this :

$ printf "int main ( int argc, char* argv[] ) { return 0; }" > tzero.c

Aside: why would you bother to declare parameters for such a program?
What's wrong with int main(void) ?

I wonder about this every time somebody reports a bug that gives
-Wunused-parameter warnings because of pointless unused parameters.

Since C99 (and in C++) you don't even need the return statement.

int main() { }


Just for giggles let's use the argc parameter :

0000000  69  6e  74  20  6d  61  69  6e  20  28  20  69  6e  74  20  61
           i   n   t       m   a   i   n       (       i   n   t       a
0000010  72  67  63  2c  20  63  68  61  72  2a  20  61  72  67  76  5b
           r   g   c   ,       c   h   a   r   *       a   r   g   v   [
0000020  5d  20  29  20  7b  20  72  65  74  75  72  6e  20  61  72  67
           ]       )       {       r   e   t   u   r   n       a   r   g
0000030  63  3b  20  7d
           c   ;       }

------------------ output assembly ----------------------
     1          .file   "tzero.c"
     2          .section        ".text"
     3          .align 4
     4          .global main
     5          .type   main, #function
     6          .proc   04
     7  main:
     8          save    %sp, -176, %sp
     9          mov     %i0, %g1
    10          stx     %i1, [%fp+2183]
    11          st      %g1, [%fp+2175]
    12          ld      [%fp+2175], %g1
    13          sra     %g1, 0, %g1
    14          mov     %g1, %i0
    15          return  %i7+8
    16           nop
    17          .size   main, .-main
    18          .ident  "GCC: (genunix Fri Jan  2 11:56:03 GMT 2015) 4.9.2"
-----------------------------------------------------------

So line 12 there handles the argc parameter into gen reg g1.

$ ./tzero 2 3 4 5
$ echo $?
5

looks correct but the source file still has no end of line. So I
wonder if zero or more lines is correct or not.  The zero part I
mean.

dc


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]