Lookhead for nested functions

rikki cattermole rikki at cattermole.co.nz
Sat Jun 15 10:27:26 UTC 2019


On 15/06/2019 10:16 PM, Amex wrote:
> On Friday, 14 June 2019 at 06:00:13 UTC, FeepingCreature wrote:
>> On Friday, 14 June 2019 at 05:35:31 UTC, Amex wrote:
>>> I realize this may not be a simple solution in all cases but surely 
>>> it can be make to work in such simple cases?
>>
>> Nope. Consider the following code:
>>
>> int foo()
>> {
>>   return bar();
>>   int i = 5;
>>   int bar() { return i; }
>> }
>>
> 
> There is nothing wrong with this.

Yes there is.
i never got initialized, it is effectively =void. Assuming its stored on 
the stack and not a register.

E.g.

Here is an example that shows what you're suggesting.

int func() {
	int x;
	somethingElse(x);
	int y = 7;
	return y;
}

Assembled:

int onlineapp.func():
	push	RBP
	mov	RBP,RSP
	sub	RSP,010h
	xor	EAX,EAX
	mov	-8[RBP],EAX
	mov	EDI,EAX
	call	  void onlineapp.somethingElse(int)@PLT32
	mov	ECX,7
	mov	-4[RBP],ECX
	mov	EAX,ECX
	leave
	ret

The instructions:
	mov	ECX,7
	mov	-4[RBP],ECX

Never ran and hence who knows what the return value is.

If you really want this, it will require a DIP.


More information about the Digitalmars-d mailing list