[comp.sys.mac.programmer] Problem with Think C! Help!

s36572u@puukko.hut.fi (Karl Tigerstedt) (02/28/91)

       I'm having problems with Think C. The situation:

I call a function (my own function, called "void filename(....) ... ").
The function seems to do it's job fine. BUT, when returning to the
calling (parent) function, execution advances not on the very next line,
which it should do, instead it SKIPS one line, and the execution then
continues....!?
Here's the code:

		if (e > 'z')
		{
			e = 'a';
			d++;
		}
		filename(filet,d,e,langd);  /* here's the function call */
		printf("What's happening 1?\n");
		printf("What's happening 2?\n"); /* It continues HERE ...? */
		printf("Output file is called %s \n",filet);
		ut = fopen(filet,"w");


   In other words, the "Happening #1" is never executed!
I was almost going crazy, until I noticed how it worked. BUT, I still
don't know WHY ????

---------------------------------------------------------------------------
"I have only come here seeking knowledge.
 Things they would not teach me of in college"    - The Police
*** Karl Tigerstedt , email s36572u@puukko.hut.fi ***

butenko@bob.srcc.msu.su (Vladimir A. Butenko) (02/28/91)

 In <1991Feb27.221632.23341@santra.uucp> Karl Tigerstedt writes:
>       I'm having problems with Think C. The situation:
>
>I call a function (my own function, called "void filename(....) ... ").
>The function seems to do it's job fine. BUT, when returning to the
>calling (parent) function, execution advances not on the very next line,
>which it should do, instead it SKIPS one line, and the execution then
>continues....!?
>Here's the code:
>
>		if (e > 'z')
>		{
>			e = 'a';
>			d++;
>		}
>		filename(filet,d,e,langd);  /* here's the function call */
>		printf("What's happening 1?\n");
>		printf("What's happening 2?\n"); /* It continues HERE ...? */
>		printf("Output file is called %s \n",filet);
>		ut = fopen(filet,"w");
>
>
>   In other words, the "Happening #1" is never executed!
>I was almost going crazy, until I noticed how it worked. BUT, I still
>don't know WHY ????

I advice you to look at Debugger window: is there an "executable opartor" sign
near the operator printf("What's happening 1?\n"); ?

If no, the reason is that the "real" comment after filename(...); (i.e.
comment in your program, not in your posting) is'n closed.

If there is an "executable operator" sign, the situation is really strange,
so you should use low-level debugger. Trace your "filename" procedure with 
Think. When the return operator is reached,  the Think Debugger shows the last
line of the procedure. Choose "Monitor". If you use MacsBug enter:

  br @(pc-4)
  g

Press Go button in Think Debugger.

now you can see the return sequence and after RTS command you'll find yourself
in the caller module. Look at it. I think that Motorolla code is so simple
and Think code generator is so strightforward that you can't meet any problem
to understand the code, even if you don't  know Motorolla assembler.

I hope it helps.


-- 
Vladimir A. Butenko             Internet:       <Butenko@bob.srcc.msu.su>
Gamma Software,                 Phone:          7(095)939-2618
Moscow State University         Fax:            7(095)938-2136
* ===  To Gorby-lovers: communists can't reform, but they can pretend! === *