<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-21187848</id><updated>2011-12-14T18:53:26.088-08:00</updated><title type='text'>C/C++ Programming Tips and Tricks</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://cpp-programming.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21187848/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://cpp-programming.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Heherson Tan</name><uri>http://www.blogger.com/profile/16362145715987111368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-21187848.post-113885431780456875</id><published>2006-02-01T19:57:00.000-08:00</published><updated>2006-02-01T20:25:47.233-08:00</updated><title type='text'>char** from static variables</title><content type='html'>When a function expects a char** parameters, it is not possible to pass a char[][] variable, which should have allowed us to avoid dynamic memory allocation. Merely casting the char[][] will produce undesirable results. Example:&lt;br /&gt;&lt;br /&gt;void iterate(char** a, count) {&lt;br /&gt;   for(int i=0; i&amp;#60count; i=""&gt;&lt;br /&gt;       operate(a[i]);&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;int main () {&lt;br /&gt;      char str_array[32][128];&lt;br /&gt;      iterate((char**)(str_array), 32);&lt;br /&gt;      return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;The a[i] will reference (char*)str_array+sizeof(int), a lot different from what we want str_array[i].&lt;br /&gt;&lt;br /&gt;However, we can do this:&lt;br /&gt;&lt;br /&gt;int main() {&lt;br /&gt;      char buffer[32*128];&lt;br /&gt;      char* str_array[32];&lt;br /&gt;      for(int i=0; i&amp;#60 ++i) {&lt;br /&gt;             str_array[i] = buffer+i*128;&lt;br /&gt;      }&lt;br /&gt;      iterate((char**)str_array, 32);&lt;br /&gt;      return 0;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;This will produce the desired effect&lt;br /&gt;&lt;/count;&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/21187848-113885431780456875?l=cpp-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-programming.blogspot.com/feeds/113885431780456875/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=21187848&amp;postID=113885431780456875' title='17 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21187848/posts/default/113885431780456875'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21187848/posts/default/113885431780456875'/><link rel='alternate' type='text/html' href='http://cpp-programming.blogspot.com/2006/02/char-from-static-variables.html' title='char** from static variables'/><author><name>Heherson Tan</name><uri>http://www.blogger.com/profile/16362145715987111368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>17</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21187848.post-113765078976073841</id><published>2006-01-18T22:00:00.000-08:00</published><updated>2006-01-18T22:31:14.220-08:00</updated><title type='text'>Optimization by loop re-factoring</title><content type='html'>Instead of:&lt;br /&gt;&lt;br /&gt; for(int i = 0; i &amp;lt; MAX; ++i)&lt;br /&gt;     if(i != ID)&lt;br /&gt;     {&lt;br /&gt;         // DO SOMETHING&lt;br /&gt;     }&lt;br /&gt;         }&lt;br /&gt;&lt;br /&gt;Use:&lt;br /&gt;&lt;br /&gt; for(int i = 0: i &amp;lt; ID; ++i)&lt;br /&gt;{&lt;br /&gt;     // DO SOMETHING&lt;br /&gt;         }&lt;br /&gt;         for(int i = ID; i &amp;lt; MAX; i=""&gt;&lt;br /&gt;{&lt;br /&gt;                 // DO SOMETHING&lt;br /&gt;         }&lt;/max;&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/21187848-113765078976073841?l=cpp-programming.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://cpp-programming.blogspot.com/feeds/113765078976073841/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=21187848&amp;postID=113765078976073841' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/21187848/posts/default/113765078976073841'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/21187848/posts/default/113765078976073841'/><link rel='alternate' type='text/html' href='http://cpp-programming.blogspot.com/2006/01/optimization-by-loop-re-factoring.html' title='Optimization by loop re-factoring'/><author><name>Heherson Tan</name><uri>http://www.blogger.com/profile/16362145715987111368</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>7</thr:total></entry></feed>
