We’re all a little technical …

So, I was compiling a computer program today, and got this error:

“warning: control reaches end of non-void function”.

And people say philosophy and theology use words oddly to be obscure [grin].

(What this means is that in a function where I say “This function must return a value”, it’s possible to hit the end of the function and not return a value.)

About these ads

2 Responses to “We’re all a little technical …”

  1. N Says:

    Not exactly right. Control is rather stupid. The following raises the warning when using Wall, even though argc is always >= 1. Then again, the compiler can only check semantics when provided with them.

    int main ( int argc, char** argv) { if (argc) return 2; }

    N

  2. verbosestoic Says:

    Well, in this case, the compiler is technically right; it is possible, it just won’t ever happen due to how the system passes in argc (it counts the command as well). I seem to recall mention of some systems that actually DON’T count the command, at least in the argv part. So it’s just warning you about a possible problem (and, to be honest, really bad code [grin]).

    A case like this, however, is more egregious:

    bool foo() {

    int a = 5;

    if(a == 5) {

    return true;
    }

    }

    I haven’t tried it, but I suspect the function would still complain. But if you aren’t a real-time compiler, it’s massively hard to write the compiler to figure this case out, since you need to keep track of contexts and their constant assignments, potentially from a statement that was far back in the code, and in a manner that you’d only need for this specific case.

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


Follow

Get every new post delivered to your Inbox.

Join 38 other followers

%d bloggers like this: