Re: preprocessing directive with no new-line character

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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() { }


Not interested in "-Wunused-parameter" issues. I think you missed the
point. Regardless here :

0000000  69  6e  74  20  6d  61  69  6e  20  28  29  20  7b  20  72  65
           i   n   t       m   a   i   n       (   )       {       r   e
0000010  74  75  72  6e  20  37  3b  20  7d
           t   u   r   n       7   ;       }


GCC compiles that fine and the output assembly :


------------------ 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     7, %g1
    10          sra     %g1, 0, %g1
    11          mov     %g1, %i0
    12          return  %i7+8
    13           nop
    14          .size   main, .-main
    15          .ident  "GCC: (genunix Fri Jan  2 11:56:03 GMT 2015) 4.9.2"
-----------------------------------------------------------

Oracle Studio 12.4 rejects the input file as invalid :
"tzero.c", line 1: warning: newline not last character in file


However the assembler is happy with the asm source above :

tzero: ELF 64-bit MSB executable SPARCV9 Version 1, UltraSPARC1 Extensions Required, dynamically linked, not stripped, no debugging information available


Let's execute that binary and check the return val

$ ./tzero
$ echo $?
7


Is there a diff at all regardless of the parameters for the func main?
Not much.

Consider this :

-----------------------------------------------------------
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  37  3b  20
           ]       )       {       r   e   t   u   r   n       7   ;
0000030  7d
           }
0000031


------------------ 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          mov     7, %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 there we see the lines 9 to 10 are for handling pointers to the unused parameters. Makes no difference. The input should be rejected.

Dennis



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux