Topic: constant arrays
Author: raph@panache.demon.co.uk (Raphael Mankin)
Date: 31 Mar 93 19:09:54 GMT Raw View
C and C++ do not contain array denotations, nor a rowing coercion. What you
want is Algol 68 - of blessed memory.
--------------
Raphael Mankin Nil taurus excretum
Author: s913606@yallara.cs.rmit.OZ.AU (Mab)
Date: 15 Mar 93 03:20:00 GMT Raw View
Here's the deal. The other day I was writing a string cat function
to put a character onto the end of a string. I tried something like
this...
void strCat(char *fred, char bob)
{
/* ... */
strcat(fred, (char*){bob, 0});
/* ... */
}
and borland c++ 3.1 spat. I can't recall the actual error, but someone
may know exactly why this wasn't allowed. Help?
.___,--.,--.____,--._.-._email the Mabster at s913606@yallara.cs.rmit.OZ.AU_.
| / /| /| | __/_| |_| |____ "That's one small step for man, and --- |
| / / |/ | | \ _| |_| |_ / SHIT! There's a f**king alien!" |
|/ / | |/ /\ | | | | / -Neil Armstrong (Before govt coverup).|
(_/------|___/--\__|-|__/---------------------------------------------------'
Author: dak@hathi.informatik.rwth-aachen.de (David Kastrup)
Date: 15 Mar 93 19:09:33 GMT Raw View
s913606@yallara.cs.rmit.OZ.AU (Mab) writes:
>Here's the deal. The other day I was writing a string cat function
>to put a character onto the end of a string. I tried something like
>this...
>void strCat(char *fred, char bob)
>{
>/* ... */
> strcat(fred, (char*){bob, 0});
>/* ... */
>}
>and borland c++ 3.1 spat. I can't recall the actual error, but someone
>may know exactly why this wasn't allowed. Help?
Why should it be allowed? It is not near anything being legitimate code.
What are those curly braces supposed to mean? A struct? An array?
If it is supposed to be the latter, you have to use char[] as your type.
But you cannot mix in some mightbe initialization into a function call.
Use a named array, such as char tmp[2] = {bob,0};
then use that as your second argument. However, I do not remember right
now whether C++ allows automatic array initializations. Might be, but
plain C does not. If C++ echoes this, you will have to use explicit
tmp[0] = bob, tmp[1] = '\0';
--
David Kastrup dak@messua.informatik.rwth-aachen.de
Tel: +49-241-72419 Fax: +49-241-79502
Goethestr. 20, W-5100 Aachen, Germany