<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Error in compiling C++ in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997149#M97922</link>
    <description>You have made a fundamental error. Note that this declaration allocates space for a pointer to a struct AAA but not the struct itself. Moreover, c points to an unitialized location so in some cases your code will actually work (in the sense that no segmentation violation will occur) but still be wrong.&lt;BR /&gt;BAD:&lt;BR /&gt;AAA *c;&lt;BR /&gt;&lt;BR /&gt;Good: &lt;BR /&gt;AAA C,*c; /* declare both a struct and a pointer to struct*/&lt;BR /&gt;c = &amp;amp;C; /* Now set the pointer to the struct's address */&lt;BR /&gt;c-&amp;gt;a = 1.1;&lt;BR /&gt;c-&amp;gt;b = 2;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 14 Aug 2006 09:21:58 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2006-08-14T09:21:58Z</dc:date>
    <item>
      <title>Error in compiling C++</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997148#M97921</link>
      <description>I keep getting segmentation error when running this program... though I get no compiling error.Anyone care to drop a hint?&lt;BR /&gt;Codes:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;#include &lt;IOSTREAM&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;typedef struct &lt;BR /&gt;{&lt;BR /&gt; double a;&lt;BR /&gt; int b;&lt;BR /&gt;} AAA;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt; AAA *c, *v;&lt;BR /&gt; &lt;BR /&gt; c-&amp;gt;a = 1.1;&lt;BR /&gt; c-&amp;gt;b = 2;&lt;BR /&gt; //*v = *c;&lt;BR /&gt; printf("TP\n"); &lt;BR /&gt; //c-&amp;gt;a = c-&amp;gt;a*2;&lt;BR /&gt; &lt;BR /&gt; printf("TP1\n");&lt;BR /&gt; cout &amp;lt;&amp;lt; c-&amp;gt;a &amp;lt;&amp;lt; endl;&lt;BR /&gt; cout &amp;lt;&amp;lt; c-&amp;gt;b &amp;lt;&amp;lt; endl;&lt;BR /&gt; printf("\n%d\n",&amp;amp;c-&amp;gt;a);printf("%d\n",&amp;amp;v-&amp;gt;a);&lt;BR /&gt; //cout &amp;lt;&amp;lt; c &amp;lt;&amp;lt; endl;&lt;BR /&gt;}&lt;BR /&gt;&lt;/STDIO.H&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Mon, 14 Aug 2006 09:15:12 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997148#M97921</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2006-08-14T09:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Error in compiling C++</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997149#M97922</link>
      <description>You have made a fundamental error. Note that this declaration allocates space for a pointer to a struct AAA but not the struct itself. Moreover, c points to an unitialized location so in some cases your code will actually work (in the sense that no segmentation violation will occur) but still be wrong.&lt;BR /&gt;BAD:&lt;BR /&gt;AAA *c;&lt;BR /&gt;&lt;BR /&gt;Good: &lt;BR /&gt;AAA C,*c; /* declare both a struct and a pointer to struct*/&lt;BR /&gt;c = &amp;amp;C; /* Now set the pointer to the struct's address */&lt;BR /&gt;c-&amp;gt;a = 1.1;&lt;BR /&gt;c-&amp;gt;b = 2;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 14 Aug 2006 09:21:58 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997149#M97922</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2006-08-14T09:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error in compiling C++</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997150#M97923</link>
      <description>You haven't allocated memory for the AAA registries.&lt;BR /&gt;&lt;BR /&gt;Take into account that you have to allocate memory for them, a pointer is just a pointer.&lt;BR /&gt;&lt;BR /&gt;Try this:&lt;BR /&gt;&lt;BR /&gt;#include &lt;IOSTREAM&gt;&lt;BR /&gt;#include &lt;STDIO.H&gt;&lt;BR /&gt;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;typedef struct&lt;BR /&gt;{&lt;BR /&gt;double a;&lt;BR /&gt;int b;&lt;BR /&gt;} AAA;&lt;BR /&gt;&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;AAA *c, *v;&lt;BR /&gt;c=new AAA;&lt;BR /&gt;v=new AAA;&lt;BR /&gt;&lt;BR /&gt;c-&amp;gt;a = 1.1;&lt;BR /&gt;c-&amp;gt;b = 2;&lt;BR /&gt;//*v = *c;&lt;BR /&gt;printf("TP\n");&lt;BR /&gt;//c-&amp;gt;a = c-&amp;gt;a*2;&lt;BR /&gt;&lt;BR /&gt;printf("TP1\n");&lt;BR /&gt;cout &amp;lt;&amp;lt; c-&amp;gt;a &amp;lt;&amp;lt; endl;&lt;BR /&gt;cout &amp;lt;&amp;lt; c-&amp;gt;b &amp;lt;&amp;lt; endl;&lt;BR /&gt;printf("\n%d\n",&amp;amp;c-&amp;gt;a);printf("%d\n",&amp;amp;v-&amp;gt;a);&lt;BR /&gt;//cout &amp;lt;&amp;lt; c &amp;lt;&amp;lt; endl;&lt;BR /&gt;}&lt;BR /&gt;&lt;/STDIO.H&gt;&lt;/IOSTREAM&gt;</description>
      <pubDate>Mon, 14 Aug 2006 09:32:43 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997150#M97923</guid>
      <dc:creator>Alfredo Garcia Martino</dc:creator>
      <dc:date>2006-08-14T09:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Error in compiling C++</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997151#M97924</link>
      <description>Re-reading the code I realized that you only need an object, so just with the&lt;BR /&gt;&lt;BR /&gt;c=new AAA;&lt;BR /&gt;&lt;BR /&gt;would be enough, because after that you will point to the reserved area with the other v pointer.&lt;BR /&gt;&lt;BR /&gt;It's really important working with C that you fully understand the difference between a pointer and the information it's pointing.&lt;BR /&gt;&lt;BR /&gt;The pointer doesn't need to reserve memory, but  you need to reserve memory for the data.&lt;BR /&gt;&lt;BR /&gt;Once you have the data, of course you can point to that data so many pointers as you want without having to reserve more memory.</description>
      <pubDate>Mon, 14 Aug 2006 10:11:06 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997151#M97924</guid>
      <dc:creator>Alfredo Garcia Martino</dc:creator>
      <dc:date>2006-08-14T10:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Error in compiling C++</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997152#M97925</link>
      <description>Thanks.. my qn is solved!</description>
      <pubDate>Mon, 14 Aug 2006 10:38:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997152#M97925</guid>
      <dc:creator>Henry Chua</dc:creator>
      <dc:date>2006-08-14T10:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: Error in compiling C++</title>
      <link>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997153#M97926</link>
      <description>&lt;!--!*#--&gt;Your compiler should have warned you that you had some uninitialized variables:&lt;BR /&gt;aCC6:&lt;BR /&gt;warning #2549-D: variable "c" is used before its value is set&lt;BR /&gt;  c-&amp;gt;a = 1.1;&lt;BR /&gt;  ^&lt;BR /&gt;warning #2549-D: variable "v" is used before its value is set&lt;BR /&gt;  printf("%d\n",&amp;amp;v-&amp;gt;a);&lt;BR /&gt;                 ^&lt;BR /&gt;aCC3:&lt;BR /&gt;Warning 430: The variable 'v' is never initialized.&lt;BR /&gt;    AAA *c, *v;&lt;BR /&gt;             ^&lt;BR /&gt;Warning 430: The variable 'c' is never initialized.&lt;BR /&gt;    AAA *c, *v;&lt;BR /&gt;         ^</description>
      <pubDate>Tue, 15 Aug 2006 00:45:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/error-in-compiling-c/m-p/4997153#M97926</guid>
      <dc:creator>Dennis Handly</dc:creator>
      <dc:date>2006-08-15T00:45:24Z</dc:date>
    </item>
  </channel>
</rss>

