Topic: ambiguity in default values?


Author: krotoff@such.srcc.msu.su (Krotoff Alexander)
Date: Wed, 6 Oct 93 21:57:16 EET
Raw View
According to Bill Leonard:
>
> In article <1993Oct04.201511.1519@vedge.com>, hendrik@vedge.com (Hendrik Boom) writes:
> > Consider
> >       const int i= 3;
> >       class A{ A(int);
> >               operator = (const A&, int);
Error:                     ^^^^^^^^^^^^^^^^^^
It must to be `= (int);' since your operator= is a member of class.

> >       };
> >       void f(int u = 2, A(i) = 3);
> >
> > Does f have one or two parameters?
> > either
> > (1)   u is a parameter with default value (2, A(i) = 3)
> > or
> > (2)   u is a parameter with default value 2
> >       i is a parameter of type A with default value A(3)
>
> Perhaps I'm just being dense, but I don't see how (2) can be valid.  What
> happens to the "(i)"?  I can't parse "A(i) = 3" as a declaration and make
> any sense of it.  What did I miss?
>
You miss a syntax of declarator.
(1) is wrong.
(2) is rign if you fix an error.

--
Alexander Krotoff                (krotoff@such.srcc.msu.su)
Research Computer Center
Moscow State University.





Author: hendrik@vedge.com (Hendrik Boom)
Date: Tue, 12 Oct 1993 17:48:21 GMT
Raw View
bill@amber.csd.harris.com (Bill Leonard) writes:
: In article <1993Oct04.201511.1519@vedge.com>, hendrik@vedge.com (Hendrik Boom) writes:
: > Consider
: >  const int i= 3;
: >  class A{ A(int);
: >   operator = (const A&, int);
: >  };
: >  void f(int u = 2, A(i) = 3);
: >
: > Does f have one or two parameters?
: > either
: > (1) u is a parameter with default value (2, A(i) = 3)
: > or
: > (2) u is a parameter with default value 2
: >  i is a parameter of type A with default value A(3)
:
: Perhaps I'm just being dense, but I don't see how (2) can be valid.  What
: happens to the "(i)"?  I can't parse "A(i) = 3" as a declaration and make
: any sense of it.  What did I miss?

Declarators are allowed to have redundant parentheses in them.
In this case, around the i.

I agree, a normal programmer wishing to declare i and initialize it would
write something like A i = 3, but A (i) = 3 is (alas!) valid.

:
: --
: Bill Leonard
: Harris Computer Systems Division
: 2101 W. Cypress Creek Road
: Fort Lauderdale, FL  33309
: bill@ssd.csd.harris.com
:
: These opinions and statements are my own and do not reflect the opinions or
: positions of Harris Corporation.
:
: ------------------------------------------------------------------------------
: Let's put an end to infinity.
: ------------------------------------------------------------------------------
--
-------------------------------------------------------
Try one or more of the following addresses to reply.
at work: hendrik@vedge.com,  iros1!vedge!hendrik
at home: uunet!ozrout!topoi!hendrik




Author: hendrik@vedge.com (Hendrik Boom)
Date: Mon, 04 Oct 1993 20:15:11 GMT
Raw View
Consider
 const int i= 3;
 class A{ A(int);
  operator = (const A&, int);
 };
 void f(int u = 2, A(i) = 3);

Does f have one or two parameters?
either
(1) u is a parameter with default value (2, A(i) = 3)
or
(2) u is a parameter with default value 2
 i is a parameter of type A with default value A(3)

Note that the ARM permits an expression, not just an assignment expression
as a default value.  This allows the comma operator, Is it a bug?

Elsewhere the ARM
permits expressions just about everywhere in initializers,
even in initializer-lists, where it is hugely ambiguous whether
the commas are operators or list-separators. ANSI C permits only
assignment-expressions here.

 hendrik.
--
-------------------------------------------------------
Try one or more of the following addresses to reply.
at work: hendrik@vedge.com,  iros1!vedge!hendrik
at home: uunet!ozrout!topoi!hendrik




Author: b91926@fnclub.fnal.gov (David Sachs)
Date: 5 Oct 1993 17:52:54 GMT
Raw View
In article <1993Oct04.201511.1519@vedge.com>, hendrik@vedge.com (Hendrik Boom) writes:
|> Consider
|>  const int i= 3;
|>  class A{ A(int);
|>   operator = (const A&, int);
|>  };
|>  void f(int u = 2, A(i) = 3);
|>
|> Does f have one or two parameters?
|> either
|> (1) u is a parameter with default value (2, A(i) = 3)
|> or
|> (2) u is a parameter with default value 2
|>  i is a parameter of type A with default value A(3)
|>

(2) - within a function call (or declaration) first level commas separate arguments.

To get (1) write "void f(int u = (2, A(i) = 3));"




Author: bill@amber.csd.harris.com (Bill Leonard)
Date: 5 Oct 1993 19:07:34 GMT
Raw View
In article <1993Oct04.201511.1519@vedge.com>, hendrik@vedge.com (Hendrik Boom) writes:
> Consider
>  const int i= 3;
>  class A{ A(int);
>   operator = (const A&, int);
>  };
>  void f(int u = 2, A(i) = 3);
>
> Does f have one or two parameters?
> either
> (1) u is a parameter with default value (2, A(i) = 3)
> or
> (2) u is a parameter with default value 2
>  i is a parameter of type A with default value A(3)

Perhaps I'm just being dense, but I don't see how (2) can be valid.  What
happens to the "(i)"?  I can't parse "A(i) = 3" as a declaration and make
any sense of it.  What did I miss?

--
Bill Leonard
Harris Computer Systems Division
2101 W. Cypress Creek Road
Fort Lauderdale, FL  33309
bill@ssd.csd.harris.com

These opinions and statements are my own and do not reflect the opinions or
positions of Harris Corporation.

------------------------------------------------------------------------------
Let's put an end to infinity.
------------------------------------------------------------------------------