if you think otherwise you're a trendfag. goto is far more efficient than function calls for short blocks of code (lol compiler ignoring inline) and have a lot of neat applications.
Name:
Anonymous2012-06-11 22:07
Every programmer worth their salt knows this.
Name:
Anonymous2012-06-11 22:08
only if you goto back to the spot where you first goto in order to make your code read in stepwise fashion
Name:
Anonymous2012-06-11 22:17
I thoroughly enjoy spaghetti code.
I enjoy not being able to follow logic properly because of lack of structure.
I enjoy investing an inordinate amount of time figuring out logical problems in spaghetti code because the idiot coder actually believes in premature optimization.
Godspeed to you good people, and may the fruits of your work be evident.
i know i'm dumb, but this is the only way i could figure out fizz buzz without a separate case
void fizz_buzz(int upto)
{
int i = 1;
while(i != upto+1)
{
if(i % 3 == 0)
{
printf("%s", "Fizz");
}
else
goto not_multiple_of_3;
goto is acceptable when you use it for error handling, like this: [code]int foo()
{
/* Allocate memory */
if (/* error */)
goto error;
return 0;
error:
fprintf(stderr, "Error occurred!\n");
/* Release memory */
return -1;
}
Name:
Anonymous2012-06-12 8:12
>>22
What's wrong with the if statement? int foo()
{
/* Allocate memory */
if (/* correct */)
return 0;
else //assume an error occurred
{
fprintf(stderr, "Error occurred!\n");
return -1;
}
}
Name:
Anonymous2012-06-12 8:31
>>23
there's a lot of yiffing, you could instead
#define TRY(X, Y) if(X) goto Y;
since encapsulating the section of error handling is unpractical.
goto's create a 3 dimensional execution path, which is almost impossible to debug. Making goto's shit. Also lisp is shit, C for life, C is shit.
Name:
Anonymous2012-06-12 9:03
>>23
If you have to allocate more than one pointer: int foo(size_t size1, size_t size2) {
char* string1;
char* string2;
if (!(string1 = malloc(size1))
goto error;
if (!(string1 = malloc(size2)) {
/* free(string1); */
goto error;
}
return 0;
error:
fprintf(stderr, "%s: malloc: %s\n", __func__, strerror(errno));
free(string1);
free(string2);
return -1;
}
Otherwise you'd have to free all the pointers you allocated before the error in every subsequent if, which could get ridiculous.
>>24
If you want to get really nasty, take a look at this library I wrote (abridged): #define throw(type, ...)\
do {\
__throw(type, __FILE__, __func__, __LINE__, __VA_ARGS__);\
longjmp(__ex_jmp_buf, type);\
} while (0)
#define try if (!(__ex_type = setjmp(__ex_jmp_buf)))
#define catch(type) \
else if ((__ex_type != EXCEPTION_NONE) && (type == EXCEPTION_ANY || __ex_type == type)) {\
exception* e = __catch();\
__unthrow();
#define otherwise } else
Example: #include <exception.h>
int idiv(int numerator, int denominator)
{
if (denominator == 0)
throw(EXCEPTION_DIVISION_BY_ZERO, "Integer division by zero");
return numerator / denominator;
}
>>26
In your first code, if the first malloc doesn't work it will try to free the second pointer which has a unknown value.
Name:
Anonymous2012-06-12 10:27
>>27
You're right - I should have initialised the two pointers to NULL first. I also typed 'string1' instead of 'string2' in the second 'if'. I'm breaking all the rules today.
Name:
Anonymous2012-06-12 10:45
Also, is free(NULL); correct ?
Name:
Anonymous2012-06-12 10:48
>>29
free(3) If ptr is NULL, no operation is performed.
>>22
Sure seems a lot faster than sepples smart pointers and exceptions.
Name:
Anonymous2012-06-12 11:30
>>37
It probably is faster, but sepples is about compile-time safety or something. C++ has improved with the new standard, though, and I'm starting to use it a little more. I still mostly use C, C# and FIOC though.
Name:
Anonymous2012-06-12 13:15
my philosophy:
as long as you can figure out what you wrote, its plenty readable
for(size_t i = 0; i < upto; ++i) printf(text[i%15], i);
}
hai gaiz cna i play wit u?
Name:
Anonymous2012-06-12 22:39
thinks using gotos for simple control flow is faster than using built in syntax for equivalent control flow
there are times to use goto, but this is not one of them. I love the art of goto programming as much as anyone, but don't act like any of this is actually useful for anything other than fun.
>>48
there is a transformation. while is all you need for any control flow, although extra variables may need to be introduced. tail calls and if can be trivially compiled to a convoluted bundle of gotos, with no additional resources as well. Any arbitrary block of goto code can be translated to a set of functions that transfer control to one another with tail calls.