Thread: GCC: error check only

  1. #1
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413

    GCC: error check only

    Is there a way to "compile" code with GCC while only actually emitting errors, i.e. get the errors/warnings from compiling but not actually compile and creating a file? I ask because I want to check a very large codebase for errors without having to actually compile. It will easily compile without problems, but my bottleneck in the compiling time is the hard drive. I don't actually need the compiled object files, just the errors.

    If nothing else, I suspect that you could direct the output to /dev/null so that writing the output file never takes place. Thoughts?

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  3. #3
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    Thanks, I saw that when looking earlier, but syntax seems vague, thought for sure it literally only checked language syntax, not errors/warnings.

  4. #4
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Many warnings are only reported when compiling with optimization, as data-flow tracking is necessary to find for instance uninitialized variables etc. A syntax-only check will reliably detect syntax errors but won't report every error/warning that could occur.

    If you use the "-pipe" option to gcc, and output the resulting .o to /dev/null, you should avoid any disk accesses.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  5. #5
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    What about using -S to avoid running the assembler at all? You'd still want to direct the resulting .s files to /dev/null.

    Actually, how would you direct output (.s or .o) to /dev/null ?
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by oogabooga View Post
    Actually, how would you direct output (.s or .o) to /dev/null ?
    I think "-o /dev/null" would probably work.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    it looks to me like option -fsyntax-only is what you're looking for.
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. simple error check
    By kiwi101 in forum C Programming
    Replies: 25
    Last Post: 11-01-2012, 10:45 AM
  2. Error Check
    By strokebow in forum C++ Programming
    Replies: 5
    Last Post: 02-19-2009, 12:04 PM
  3. How to check error
    By saswatdash83 in forum C Programming
    Replies: 2
    Last Post: 07-16-2008, 04:49 AM
  4. How to error check that input is int or something else
    By sameintheend01 in forum C++ Programming
    Replies: 1
    Last Post: 01-17-2003, 03:04 AM
  5. Check for error in scanf()
    By Dangerous Dave in forum C Programming
    Replies: 5
    Last Post: 12-08-2001, 06:15 PM