[DGD] Re: varargs int ...
Michael McKiel
crashnbrn71 at yahoo.ca
Sat Feb 21 20:09:32 CET 2004
--- Erwin Harte <harte at is-here.com> wrote:
> The only way I can see to be 100% sure what parameters were provided
> or not, is by using the ellipsis:
>
> string strstr(string str, int start, varargs mixed extra...) {
> int end;
>
> if (sizeof(extra) == 0) {
> /* No extra parameters provided. */
> } else if (sizeof(extra) == 1 && typeof(extra[0]) == T_INT) {
> /* Extra parameter was provided and was an integer. */
> end = extra[0];
> } else {
> error("bad argument 3 to strstr");
> }
> ...
> }
>
> The next best thing is:
>
> string strstr(string str, int start, varargs mixed end) {
> if (end == nil) {
> /* Varargs parameter omitted or 'nil' value used. */
> } else if (typeof(end) == T_INT) {
> /* Extra parameter provided and was an integer. */
> } else {
> error("bad argument 3 to strstr");
> }
> ...
> }
>
> But then you can't distinguish between strstr("foo", 1, nil) and
> strstr("foo", 1).
>
> If you don't care about that distinction, then by all means go ahead
> and use that approach. ;-)
>
> Hope that helps,
Just to clarify, its a substr() function :), and yeah that helps a lot...
strangely enough I used the ellipses in a strcat() function but couldn't see
to use that in this instance. -- Not that a strcat() is of any use, but a
number of them were more for figuring it out hehe.
Although I suppose
if (substr(path, -2) == ".c") { path = substr(path, 0, -2); }
might look better than:
if (path[strlen(path)-3..] == ".c") { path = path[0..strlen(path)-3]; }
Anyways, thankee
Zamadhi
______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca
_________________________________________________________________
List config page: http://list.imaginary.com/mailman/listinfo/dgd
More information about the DGD
mailing list