Differences

This shows you the differences between two versions of the page.

Link to this comparison view

address [2011/07/15 10:42]
address [2022/04/16 12:22] (current)
Line 1: Line 1:
 +@related: [[CPlusPlus]] [[ptr]]
 +
 +allocation functions seems to work even if [[null]] pointer [[address]] passed as [[reference]] ?
 +
 +
 +<code>
 +#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);
 +}
 +</code>
 +
 +
 +==== misc ====
 +
 +  * http://www.frogatto.com/?p=3
 +  * http://cslibrary.stanford.edu/104/
 +  * http://www.penspinning.fr/s777-at-thetournament-2011-3544
  
address.txt ยท Last modified: 2022/04/16 12:22 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki