Chris Torek <nospam@torek.n etwrites:
[...]
[...]
[...]
[...]
The last (two) variant(s) has(ve) the advantage that the value
assigned to fd can be inspected and possibly changed by a human using
a 'suitable tool' (debugger) before the program acts on it.
<fjblurt@yahoo. comwrote:
>>There is a discussion about the stylistic advantages and disadvantages
>>of the following two snippets:
>>of the following two snippets:
>>void foo_set_and_tes t (void) {
> int fd;
> if ((fd = open(...)) < 0) {
> fail();
> }
>>}
> int fd;
> if ((fd = open(...)) < 0) {
> fail();
> }
>>}
>>void foo_init_and_th en_test_separat ely (void) {
> int fd = open(...);
> if (fd < 0) {
> fail();
> }
>>}
> int fd = open(...);
> if (fd < 0) {
> fail();
> }
>>}
I have a slight preference for foo_init_and_th en_test_separat ely()
myself, but this is a matter of taste. There is even a third
option:
>
void foo_set_and_the n_test_separate ly(void) {
int fd;
>
fd = open(...);
if (fd < 0) {
fail();
...
}
...
}
myself, but this is a matter of taste. There is even a third
option:
>
void foo_set_and_the n_test_separate ly(void) {
int fd;
>
fd = open(...);
if (fd < 0) {
fail();
...
}
...
}
Again, though, all of this is largely a matter of taste. Arguing
about it is like arguing whether raspberry ice cream is superior
to peach ice cream.
about it is like arguing whether raspberry ice cream is superior
to peach ice cream.
assigned to fd can be inspected and possibly changed by a human using
a 'suitable tool' (debugger) before the program acts on it.
Comment