Do we really need const?
renoX
renosky at free.fr
Mon Sep 17 14:48:00 PDT 2007
Bruce Adams a écrit :
> An example of one that catches me out quite often is:
> strcpy(src,dest) vs. strcpy(dest,src);
If it helps you'not the only one to have this kind of issue: some
compilers even try to detect when people makes mistakes for 'memset'?
Both case show why function calls with passing the parameter by position
instead of by keywords *sucks*.
Let's try it: do you think you would make the same mistake if you would
call your function this way:
char[50] var_dest, my_src;
strcpy(dest: var_dest, src: my_src)
See?
1) much less risk of errors
2) better readability
3) in case of error, it's easy to see the error and correct it.
So there is a better way than const to prevent source/dest error,
unfortunately D doesn't support it..
Regards,
RenoX
More information about the Digitalmars-d
mailing list