Re: Those of us who are C'ly challenged :>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Nate wondered:

> One main reason why I think that C is better then Eu is that you can
> declare stuff below the initial procedure. I.E.:

Actually, your example will NOT work in ANSI C. The compiler will
complain that "goaway" is an unknown function, just like Euphoria does.
For the code to compiler, you need to define prototype for your function
first:

void goaway(void); /* prototype */

int main() {
   printf("Hello\n");
   goaway();
}

void goaway() {
   printf("\nGo away now!\n");
}

It might work automagically if your compiler supports automatic
prototype generation, but that's not standard ANSI C.

If you had re-written your code in the manner that Euphoria requires, it
would work just fine in C, without the need for a prototype:

void goaway() {
   printf("\nGo away now!\n");
}

int main() {
   printf("Hello\n");
   goaway();
}

That's because C and Euphoria are both one-pass compilers. You can't
reference anything until it's been defined. C lets you get around that
by setting up prototypes, but those are prone to error. I prefer to lay
my C code out similar to Euphoria code.

On those rare occasions that you really *do* need to call a function
before it is defined, you can use routine_id and call_routine to
accomplish the same thing that C prototypes do.

-- David Cuny

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu