-v compiler switch in gcc 4.3.0

  • Follow


I've been working up my game with open-source distros and decided to solve a 
K&R problem to highlight my own misunderstanding of the -v compiler switch. 
I selected a problem from chp 7 at more or less random and decided on 7.6. 
I don't have an english k&R, but the german one lautet:  Aufgabe 7-6. 
Schreiben Sie ein Programm, das zwei Dateien vergleicht und die erste Zeile 
ausgibt, wo sie verschieden sind.

For a soln, I used Heathfield's 2nd soln:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFF_SIZE 1000

/* uses fgets, removes the '\n' at the end of the string if it exists

*/
char *safegets(char *buffer, int length, FILE *file)
{
        char *ptr;
        int len;

        if (buffer != NULL)
        {
                ptr = fgets(buffer, length, file);

                if (ptr != NULL)
                {
                        len = strlen(buffer);

                        if (len > 0)
                        {
                                if (buffer[len - 1] == '\n')
                                {
                                        buffer[len - 1] = '\0';
                                }
                        }
                }

                return ptr;
        }

        return NULL;
}

int main(int argc, char *argv[])
{
        FILE *leftFile, *rightFile;
        char buff1[BUFF_SIZE], buff2[BUFF_SIZE];
        char *ptr1, *ptr2;
        unsigned long lineNum = 0;

        if (argc < 3)
        {
                fprintf(stderr, "Usage : 7_6 <path to file> <path to

file>\n");
                return 0;
        }

        if (!(leftFile = fopen(argv[1], "r")))
        {
                fprintf(stderr, "Couldn't open %s for reading\n",

argv[1]);
                return 0;
        }

        if (!(rightFile = fopen(argv[2], "r")))
        {
                fprintf(stderr, "Couldn't open %s for reading\n",

argv[2]);
                fclose(leftFile); /* RJH 10 Jul 2000 */
                return 0;
        }

        /* read through each file, line by line */
        ptr1 = safegets(buff1, BUFF_SIZE, leftFile);
        ptr2 = safegets(buff2, BUFF_SIZE, rightFile);
        ++lineNum;

        /* stop when either we've exhausted either file's data */
        while (ptr1 != NULL && ptr2 != NULL)
        {
                /* compare the two lines */
                if (strcmp(buff1, buff2) != 0)
                {
                        printf("Difference:\n");
                        printf("%lu\t\"%s\" != \"%s\"\n", lineNum,

buff1, buff2);
                        goto CleanUp;
                }

                ptr1 = safegets(buff1, BUFF_SIZE, leftFile);
                ptr2 = safegets(buff2, BUFF_SIZE, rightFile);
                ++lineNum;
        }

        /*
         * if one of the files ended prematurely, it definitely
         * isn't equivalent to the other
         */
        if (ptr1 != NULL && ptr2 == NULL)
        {
                printf("Difference:\n");
                printf("%lu\t\"%s\" != \"EOF\"\n", lineNum, buff1);
        }
        else if (ptr1 == NULL && ptr2 != NULL)
        {
                printf("Difference:\n");
                printf("%lu\t\"EOF\" != \"%s\"\n", lineNum, buff2);
        }
        else
        {
                printf("No differences\n");
        }

CleanUp:

        fclose(leftFile);
        fclose(rightFile);
        return EXIT_SUCCESS;
}
// gcc -o print kr76.c
// print a.a c.c
// gcc -o kr -v kr76.c 2>text33.txt >text34.txt

The part at the end I call the goocher.  These are dos commands that are 
commented out.  I sthis why I always receive a warning about newlines at end 
of files?

a.a and c.c I created with notepad, viz.
The quick
brown fox
jumps over
the lazy dog.

and

The quick
brown faux
jumps over
the lazy dog.

When I run the executable, I get:
Difference:
2 "brown fox" != "brown faux"

So, no errors, no warnings, no misbehavior.

When I command:
gcc -o kr -v kr76.c 2>text33.txt >text34.txt
, I get:

Built by Equation Solution (http://www.Equation.com).
Using built-in specs.
Target: i386-pc-mingw32
Configured with: 
.../gcc-4.2.3-mingw/configure --host=i386-pc-mingw32 --build=x86_64-unknown-linux-gnu 
 --target=i386-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3 
 --with-gcc --with-gnu-ld --with-gnu-as --disable-shared --disable-nls --disable-tls 
 --with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr 
 --enable-languages=c,c++,fortran --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3 
 --enable-threads=win32 --enable-libgomp --disable-win32-registry
Thread model: win32
gcc version 4.2.3
 c:/path/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/cc1.exe -quiet -v -iprefix 
c:\path\gcc\bin\../lib/gcc/i386-pc-mingw32/4.2.3/ kr76.c -quiet -dumpbase 
kr76.c -mtune=i386 -auxbase kr76 -version -o 
C:\DOCUME~1\fred\LOCALS~1\Temp/ccAL65cL.s
ignoring nonexistent directory 
"/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/lib/gcc/i386-pc-mingw32/4.2.3/../../../../include"
ignoring nonexistent directory 
"/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/lib/gcc/i386-pc-mingw32/4.2.3/include"
ignoring nonexistent directory 
"/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/i386-pc-mingw32/include"
ignoring nonexistent directory 
"/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3/mingw/include"
ignoring nonexistent directory "C:/gcc/include"
#include "..." search starts here:
#include <...> search starts here:
 C:/path/gcc/include
 c:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/include
 c:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/includeEnd of search list.GNU C version 4.2.3 (i386-pc-mingw32) compiled by GNU C version 4.2.3.GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=131006Compiler executable checksum: b9b7925f719568bc0be9159aad1ef341kr76.c:110:48: warning: no newline at end of file c:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/bin/as.exe -o C:\DOCUME~1\fred\LOCALS~1\Temp/ccQHaDin.oC:\DOCUME~1\fred\LOCALS~1\Temp/ccAL65cL.s c:/path/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/collect2.exe --sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3 -Bdynamic -s -o kr.exeC:/path/gcc/i386-pc-mingw32/lib/crt2.o -Lc:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3 -Lc:/path/gcc/bin/../lib/gcc -LC:/path/gcc/i386-pc-mingw32/lib -Lc:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/lib -Lc:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../..C:\DOCUME~1\fred\LOCALS~1\Temp/ccQHaDin.o -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt// end comment by gccWhat does this all mean?--"A man is accepted into church for what he believes--and turned out forwhat he knows."-Mark Twain

0
Reply invalid163 (946) 3/18/2008 9:07:41 AM

stop wrote:
> 
> I've been working up my game with open-source distros and decided to solve a
> K&R problem to highlight my own misunderstanding of the -v compiler switch.
> I selected a problem from chp 7 at more or less random and decided on 7.6.
> I don't have an english k&R, but the german one lautet:  Aufgabe 7-6.
> Schreiben Sie ein Programm, das zwei Dateien vergleicht und die erste Zeile
> ausgibt, wo sie verschieden sind.

<snip>

> So, no errors, no warnings, no misbehavior.
> 
> When I command:
> gcc -o kr -v kr76.c 2>text33.txt >text34.txt
> , I get:

<snip>

What does this all mean?

The -v (verbose) option asks the toolchain to leave "footprints"
showing you all the things the authors of the software thought
might be of interest in analyzing the compilation and linking
process.

It's almost always a lot more than anyone wants to know, but can
be helpful if/when you have reason to believe that the process
isn't being carried as you specified.

-- 
Morris Dovey
DeSoto Solar
DeSoto, Iowa USA
http://www.iedu.com/DeSoto/
0
Reply mrdovey (601) 3/18/2008 8:43:53 AM


"stop" <invalid@invalid.net> wrote in message 
news:1205827196_119@news.newsgroups.com...
> I've been working up my game with open-source distros and decided to solve 
> a K&R problem to highlight my own misunderstanding of the -v compiler 
> switch. I selected a problem from chp 7 at more or less random and decided 
> on 7.6. I don't have an english k&R, but the german one lautet:  Aufgabe 
> 7-6. Schreiben Sie ein Programm, das zwei Dateien vergleicht und die erste 
> Zeile ausgibt, wo sie verschieden sind.
>
> For a soln, I used Heathfield's 2nd soln:
....
> Built by Equation Solution (http://www.Equation.com).
> Using built-in specs.
> Target: i386-pc-mingw32
> Configured with: 
> ../gcc-4.2.3-mingw/configure --host=i386-pc-mingw32 --build=x86_64-unknown-linux-gnu 
>  --target=i386-pc-mingw32 --prefix=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3 
>  --with-gcc --with-gnu-ld --with-gnu-as --disable-shared --disable-nls --disable-tls 
>  --with-gmp=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gmp --with-mpfr=/home/gfortran/gcc-home/binary/mingw32/native/x86_32/mpfr 
>  --enable-languages=c,c++,fortran --with-sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3 
>  --enable-threads=win32 --enable-libgomp --disable-win32-registry
> Thread model: win32
> gcc version 4.2.3
> c:/path/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/cc1.exe -quiet -v -iprefix 
> c:\path\gcc\bin\../lib/gcc/i386-pc-mingw32/4.2.3/ kr76.c -quiet -dumpbase 
> kr76.c -mtune=i386 -auxbase kr76 -version -o 
> C:\DOCUME~1\fred\LOCALS~1\Temp/ccAL65cL.s
> ignoring nonexistent directory 
> "/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/lib/gcc/i386-pc-mingw32/4.2.3/../../../../include"
> ignoring nonexistent directory 
> "/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/lib/gcc/i386-pc-mingw32/4.2.3/include"
> ignoring nonexistent directory 
> "/home/gfortran/gcc-home/binary/mingw32/native/x86_32/gcc/4.2.3/i386-pc-mingw32/include"
> ignoring nonexistent directory 
> "/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3/mingw/include"
> ignoring nonexistent directory "C:/gcc/include"
> #include "..." search starts here:
> #include <...> search starts here:
> C:/path/gcc/include
> c:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/include
> c:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/includeEnd 
> of search list.GNU C version 4.2.3 (i386-pc-mingw32) compiled by GNU C 
> version 4.2.3.GGC heuristics: --param ggc-min-expand=99 --param 
> ggc-min-heapsize=131006Compiler executable checksum: 
> b9b7925f719568bc0be9159aad1ef341kr76.c:110:48: warning: no newline at end 
> of file 
> c:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/bin/as.exe 
>  -o 
> C:\DOCUME~1\fred\LOCALS~1\Temp/ccQHaDin.oC:\DOCUME~1\fred\LOCALS~1\Temp/ccAL65cL.s 
> c:/path/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/collect2.exe --sysroot=/home/gfortran/gcc-home/binary/mingw32/cross/x86_32/gcc/4.2.3 
>  -Bdynamic -s -o 
> kr.exeC:/path/gcc/i386-pc-mingw32/lib/crt2.o -Lc:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3 
>  -Lc:/path/gcc/bin/../lib/gcc -LC:/path/gcc/i386-pc-mingw32/lib -Lc:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../../../i386-pc-mingw32/lib 
>  -Lc:/path/gcc/bin/../lib/gcc/i386-pc-mingw32/4.2.3/../../..C:\DOCUME~1\fred\LOCALS~1\Temp/ccQHaDin.o -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt// end comment bygccWhat does this all mean?--"A man is accepted into church for what hebelieves--and turned out forwhat he knows."-Mark Twain>I compiled another program from the same site, exercise 4-5, which is areverse polish calculator.  When I compiled I used the verbose command anddiverted to another text file.  I then compared them using the executable Ialready had.  Out of all that junk, only line 7 was different:Difference:7 "c:/path/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/cc1.exe -quiet -v -iprefix c:\path\gcc\bin\../lib/gcc/i386-pc-mingw32/4.2.3/kr76.c -quiet -dumpbase kr76.c -mtune=i386 -auxbase kr76 -version -oC:\DOCUME~1\dan\LOCALS~1\Temp/ccREC6nm.s"!="c:/path/gcc/bin/../libexec/gcc/i386-pc-mingw32/4.2.3/cc1.exe -quiet -v -iprefix c:\path\gcc\bin\../lib/gcc/i386-pc-mingw32/4.2.3/kr45.c -quiet -dumpbase kr45.c -mtune=i386 -auxbase kr45 -version -oC:\DOCUME~1\dan\LOCALS~1\Temp/cco4rSKI.s"As to a cause to have so much talk about nothing, I think the culprit ishaving the settings for different identities and different versions leakingon to each other.  I did something intentionally stupid with the install andI think the fix is reinstallation and manually changing path systemvariables.--"A man is accepted into church for what he believes--and turned out forwhat he knows."-Mark Twain

0
Reply invalid163 (946) 3/19/2008 5:07:24 AM

2 Replies
31 Views

(page loaded in 0.074 seconds)


Reply: