Re: [sv-ec] Matching defaults

From: Randy Misustin <ram_at_.....>
Date: Fri Jul 18 2008 - 23:53:22 PDT
Arturo Salz wrote:
> Also, you forgot to mention the biggest difference between C++ and SV 
> default arguments. In C++, default arguments are interpreted in the 
> context of the caller, whereas in SV they are interpreted in the 
> context of the declaration. SV 3.1 had the same semantics as C++, but 
> was later changed to use the declaration context to avoid having the 
> same expression interpreted differently in the caller's context.

Hi Arturo,

I'm not certain I'm understanding what you mean by "interpreted in the 
context of the caller", but if you're talking about symbol visibility, I 
believe  C++, like SV, uses the context of the declaration to determine 
which symbols are visible. For example, in the following snippit:

class Foo {
public:
	static int i;
	void fn1(int val = i) { cout << val << endl; }  // GOOD
	void fn2(int val = j) { cout << val << endl; }  // ERROR
};

int main()
{
	int j = 23;
	Foo *f = new Foo();

	f->fn1();
	f->fn2();
}


fn1 is a legal declaration, whereas fn2 will generate an error message 
due to 'j' being undeclared.

-randy.

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Jul 18 23:54:28 2008

This archive was generated by hypermail 2.1.8 : Fri Jul 18 2008 - 23:55:08 PDT