i fully agree with your position of "why is there no macro for strlen() like
it is for sizeof() ...)
even if not, the 2'nd chance would be an abstraction to the operator+= like
myStr operator+=(const char * source)
myStr operator+=(char * source)
as compiler already sees operation like Str test += "hello"; as const char
operation (ok, this is cool)
but how to use this information then ?
why is there no thing like
myStr operator+=(const char * source,strlen(source)) <- where preprocessor
automatically does an inline expand ??
and why
3'rd chanche
as:
test.AppendString("HHHHHHHHHHHHH",strlen("HHHHHHHH HHHHH"));
really does a inline "pre-length" calculation (look to /o2)
and it is in ASM
test.AppendString("HHHHHHHHHHHHH",13)); <- cool
but why the hell can i not inline the += operator into it ????
and yes, you are right, doing this
myStr operator+=(const char * source)
{
printf("Add Static Length\n");
AppendString(source,sizeof(source)); <- sizeof == 4 now , because function
gets not inlined !!!
return *this;
}
this is all "sh.t"
you think there is no chance with a function template ? (i am not very good
in them ..) ?
franz
"Ross A. Finlayson" <ra*@tiki-lounge.com.invalidschrieb im Newsbeitrag
news:ft**********@aioe.org...
>
>Anyways, while that may be so, it would also be useful to have a strlen
macro. The compiler already knows the layout of the data, it's a compile
time invariant, and would allow things like conventions about storing
word dictionaries as offset/length pairs in large strings, with no
null-terminated storage, besides just enabling simple writes of those
things.
Where are the interminable discussions about strlen macro and why/why not
it is already standard?
I guess there is sizeof for array types that returns the size of the
array, but literals are generally const char* types.
sizeof("xyz") == sizeof(char*); // <- not strlen
char xyz[] = "xyz"
sizeof(xyz) == 4 ; // <- not strlen
So, maybe it is as simple as to declare the C strings as character arrays,
and subtract 1, where sizeof(char)==1.
#define strlen_macro(char_arr) (sizeof(char_arr)/sizeof(char)-1)
Yet, still I wonder about the correct const char* <-char[] declarations,
in terms of whether when the compiler sees a character string literal,
whether it is treated as a char* or char[] in terms of sizeof (the
operator/compiler facility). Does sizeof("xyz") always return
sizeof(char*), or sizeof(char)*4, as defined behavior?
Ross F.