Re: Is it legal code?
On Feb 20, 3:30 pm, "Paul" <pchris...@yahoo.co.uk> wrote:
strlen without an object of ,
or derived from , string.
strlen(const char*) is a C++ standard function, the same as the C
standard function strlen(const char*). If you don't know that, you
should probably stop trying to make weird ontological assertions about
what is and is not said in the standard, as you don't appear to be
sufficiently familiar with it.
That is assuming strlen is defined as a non static member function of
string, in class string.
Which it isn't. It's a stand-alone function, but its still undefined
behaviour to call it on a pointer when that pointer does not point to
a NULL-terminated string.
Consider the following:
int main()
{
char* foo = new char(20);
/* q declared int, rather than std::size_t in order to save myself
typing */
int q = strlen(foo);
std::cout << "The length of foo is " << q;
}
The above program invokes undefined behaviour.
None of its constituent parts are non-existent.
Therefore, your syllogism "UB -> Non-existence" is wrong.