|
|
Log in / Subscribe / Register

Buried in warnings

Buried in warnings

Posted Nov 2, 2006 16:10 UTC (Thu) by NAR (subscriber, #1313)
In reply to: Buried in warnings by JoeBuck
Parent article: Buried in warnings

I know it's just a made-up code, but if the pointer is really not used in do_something_else(), couldn't you just write:

do_something_else();
if (some_condition_is_true()) {
   some_type* pointer = expensive_allocation_function();
   use_the_fine(pointer);
}

I guess if the pointer is not used in do_something_else(), the function can't really use the things allocated there. Or does this syntax only work in C++? In this case it's too bad...

Anyway, just to reflect to the questioning of code quality in closed software (in a separate thread), we've had quarter-million lines of C++ code compiling without a single warning...

Bye,NAR


to post comments

Buried in warnings

Posted Nov 3, 2006 1:09 UTC (Fri) by nix (subscriber, #2304) [Link] (2 responses)

C99 supports this. C90 does not.

C90 vs C99

Posted Nov 3, 2006 1:24 UTC (Fri) by xoddam (subscriber, #2322) [Link] (1 responses)

Not so. Declarations with initialisations have always been legal at the
beginning of a block.

C99 also permits declarations to follow statements, like C++.

C90 vs C99

Posted Nov 14, 2006 20:52 UTC (Tue) by nix (subscriber, #2304) [Link]

In C90 the initializations must be literals: you can't put an arbitrary
function call in there and expect it to work. (That's a GNU C extension,
copied from C++ and also found in C99: look up `Non-Constant Initializers'
in the manual.)


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds