allocation functions seems to work even if null pointer address passed as reference ?
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#define cdebug cout
#define TRACE(x) { cdebug<<#x<<"="<<(x)<<endl; }
int falloc(char*& p, int & l)
{
cdebug<<__FILE__ <<":" <<__LINE__ << " ("<< __PRETTY_FUNCTION__<<")"<<endl;
cdebug<<(hex)<<(void*)&p<<endl; // non null address : ok
l=1;
p = new char[l];
p[0]='1';
}
int main(int argc, char* argv[])
{
{
char* p = 0; int l=1;
TRACE( falloc(p,l) );
cdebug<<p[0]<<endl; // ok:1
}
{
char* p = (char*) "0"; int l=1;
TRACE( falloc(p,l) );
cdebug<<p[0]<<endl; // ok:1
}
exit(0);
}