Topic: When is not "{1,2}" an "int*"?
Author: Stanislaw Bochnak <S.Bochnak@microtool.com.pl>
Date: 1997/10/21 Raw View
Martin Fabian wrote:
>
> If you define/declare a function like
> void function(int *array);
> or equivalently
> void function(int array[]);
> shouldn't you be able to say
> function({1,2,3});
> Though, the more usual (but less handy)
> int array[] = {1,2,3};
declarator initializer
A C++ grammar defines that initializer appears AFTER a declarator
(or abstract-declarator for parameters), and ONLY in this context
curly braces have different interpretation - array or structure
initializer.
> function(array);
> is fine. Shouldn't the array "{1,2,3}" be used
> to initialize the function parameter "array" in
> the call to function({1,2,3}), just as it initializes
> the "array" variable in int array[] = {1,2,3}?
> --
> Martin Fabian
Stanislaw Bochnak
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: "Paul D. DeRocco" <pderocco@ix.netcom.com>
Date: 1997/10/19 Raw View
Martin Fabian wrote:
>
> If you define/declare a function like
> void function(int *array);
> or equivalently
> void function(int array[]);
> shouldn't you be able to say
> function({1,2,3});
> MSVC++4.2 generates LOTS of "syntax error".
> Though, the more usual (but less handy)
> int array[] = {1,2,3};
> function(array);
> is fine. Shouldn't the array "{1,2,3}" be used
> to initialize the function parameter "array" in
> the call to function({1,2,3}), just as it initializes
> the "array" variable in int array[] = {1,2,3}?
I agree, but it ain't the way it is.
While we're at it, wouldn't it be nice if you could write this?
void function(void(*)());
function({ x = y; });
;-)
--
Ciao,
Paul
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]
Author: Martin Fabian <fabian@control.chalmers.se>
Date: 1997/10/17 Raw View
If you define/declare a function like
void function(int *array);
or equivalently
void function(int array[]);
shouldn't you be able to say
function({1,2,3});
MSVC++4.2 generates LOTS of "syntax error".
Though, the more usual (but less handy)
int array[] = {1,2,3};
function(array);
is fine. Shouldn't the array "{1,2,3}" be used
to initialize the function parameter "array" in
the call to function({1,2,3}), just as it initializes
the "array" variable in int array[] = {1,2,3}?
--
Martin Fabian
-----------------------------------------------------------
email: fabian@control.chalmers.se | Control Engineering Laboratory
tel: +46 (0)31 772 37 16 | Chalmers University of Technology
fax: +46 (0)31 772 37 30 | S-412 96 Gothenburg
| Sweden
Homepage: http://www.control.chalmers.se/~fabian
------------------------------------------------------------------------
Everyone is talking about real-time, but how real is time, really?
---
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]