Mixed line endings(DOS/Unix) in the source file

Andrey Smirnov andrey.smirnov@synapse.com
Thu Nov 7 16:16:00 GMT 2013


Hello,

I recently stumbled upon what for me was surprising behavior of GCC. I
was writing some code on my Linux machine and was using data from a
data dump text file that had DOS line endings. As a commentary to one
of my functions I copied an excerpt from the dump file and
inadvertently added some DOS line endings to my source file. So what I
discovered is that, after that, GCC would output incorrect diagnostic
information in which it would think that an error/warning was present
several lines below its actual location.

The following example(^M denotes DOS line ending) on gcc-4.8.0
compiled with: "gcc test.c -o test.o"

struct a {
        int c;
        void (*f) (void);
};

void foo (void)
{
        /* ^M */
}

struct a A = {
        .c = foo,
        .f = foo,
};

would cause GCC to output:

test.c:14:9: warning: initialization makes integer from pointer
without a cast [enabled by default]
         .f = foo,
         ^

whereas with ^M removed it would say:

test.c:13:9: warning: initialization makes integer from pointer
without a cast [enabled by default]
         .c = foo,
         ^

Is this an expected behavior that I was not aware due to my ignorance?

Thank you,
Andrey Smirnov



More information about the Gcc-help mailing list