Rcjp's Weblog

December 21, 2006

Compiler warnings GCC/SCC

Filed under: c — rcjp @ 8:51 am

Got Salford SCC running under WINE (except for the /break debugger option) which is impressive.

Just tried running it on a couple of test programs and it didn’t like

    typedef struct box {
        const char *name;
        const int count;
    } BOX;

    r@laptop:~/c/exercises$ scc bsearch.c /ansi_c/link
    [Salford SCC/WIN32 Ver 3.16 Copyright (c) Salford Software Ltd 2002]
       0008       const int count;
    *** A structure member may not be const or volatile
        1 ERRORS  [<BSEARCH> SCC/WIN32 Ver 3.16]
    *** Compilation failed

I’m not quite sure about this though. I was initialising with

    struct box ruler = { "ruler", 0 };

C++ has member initialisers which are required for const member objects as in

    typedef struct box {
        const char *name;
        const int count;
        box();
    } BOX;

    box::box () : name(""), count(5){}

as you can’t do

    box::box () {
        name = "";
        count = 5;
    }

because that would mean that the constructors for the member object are called for count and then altered in the box constructor and you can’t alter a const! But there aren’t the same concepts in C, hmmm.

I also realised that gcc’s -Wall doesn’t mean what I thought it did – warn about everything. Infact the recommended compiler options for finding problems are (see http://www.network-theory.co.uk/docs/gccintro/index.html)

gcc -ansi -pedantic -Wall -W -Wconversion -Wshadow -Wcast-qual -Wwrite-strings

using -std=c99 if using c99 features. I wonder why c99 isn’t the default yet?

Advertisements

2 Comments »

  1. Did you get the debugger to work as well? (Or does that fall under the ‘/break’ clause above?). I am also trying to get the tools working on Ubuntu Gutsy, but I get stuck in a missing API (something is stubbed out to return NULL, and thus crashes further down the road) when launching the debugger.

    Comment by Roland Kaufmann — February 19, 2008 @ 7:52 pm

  2. No, I couldn’t get sdbg to run, (/break just runs the debugger after compiling/linking btw) and I found wine too awkward to use as a development environment (crashes X Window frequently etc). But I do think it is amazing that it runs the compiler at all!

    The debugger, on the other hand, is doing very low level stuff so I’d have thought you’d need to know the internals of sdbg and wine to get it working… but good luck anyway.

    Comment by rcjp — February 20, 2008 @ 9:47 pm


RSS feed for comments on this post.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: