Re: A89: Re: Please help with C


[Prev][Next][Index][Thread]

Re: A89: Re: Please help with C




On Tue, Apr 04, 2000 at 08:36:27AM +0200, Zeljko Juric wrote:
> 
> Hi!
> 
> > Below is my source. I can not figure out why it wont compile. It is
> > something with loading the variable "buffer" to restore the screen at the
> > end of the program. 
> 
> First, you cannot start a new function inside of another function. You
> start definition of "main2" before end of definition of "_main". This is
> the main problem in your program. I have not enough time at the moment
> to elaborate it in more details. I am hope that I am not the only person
> who knows C, so somebody else will give additional info to you. If you
> still can't solve the problem, mail again, and I will give to you more
> detailed answer a bit later (maybe tommorow)...

Well... You're right. But only partially. ANSI C doesn't allow nested
functions. BUT as TI-GCC is really a GCC, Gnu C Compiler, it has quite a lot
of extensions. One of them is that you CAN define and use nested functions.
I know very well that they aren't _really_ needed, at least I haven't ever
had the need to use them. 

AFAIK nested functions don't need any special internal functions to work. So
they should work with TI-GCC. Yeah, it is better to not to use nested
functions.

A few words for all persons who are trying to learn C... Try to find some
book. (I'm sorry, I cannot recommend any. I've read only one book, and it
was in Finnish... and besides it was about 7 years ago.) And read other's
source. C is not like assembler - you can understand it with much less
trouble.

Oh, BTW, complex is also a valid data type in GCC... But probably that needs
some special internal functions to work.

So, AFAIR:

__complex__ int c;
__complex__ int h=1+2i;
__complex__ char m;

is valid in GCC.

Then you can access it's real and imaginary parts like:

r=__real__ c;
i=__imag__ c;

Oh, then, as you know, GCC allows also embedding of assembler statements in
C source. I.e. in-line assembler. I'm not sure if Zeljko's TI-GCClib uses
them, but for others too:

int phew(int i, int j)
{
	asm ("addw %1,%0;" 
		  : "=d" (j) /* output goes into j */
		  : "d" (i), "d" (j) /* inputs are in i and j */
	);
	return j;
}	
Well, that's very cryptic. But what that _should_ do is to add i to j. The
compiler handles moving i and j to registers... And those %0 and %1 mean
that compiler is allowed to decide registers it likes most. Hmm, well.
That's very damn cryptic to explain. Especially when you're not so sure
yourself. I'll try to find some tutorial sometime, if anybody is 
interested. But more about in-line assembler is said in GCC infopage. Refer
to that for all GCC's extensions.

Henri Moilanen



References: