<?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: Calloc problems in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167624#M718174</link>
    <description>I suspect that it a case of the variable becoming undefined upon function exit. Calloc, malloc, ... work just fine inside functions. If you will post a section of your code that illusrates the problem then I suspect the fix will be trivial.&lt;BR /&gt;</description>
    <pubDate>Mon, 19 Jan 2004 10:25:20 GMT</pubDate>
    <dc:creator>A. Clay Stephenson</dc:creator>
    <dc:date>2004-01-19T10:25:20Z</dc:date>
    <item>
      <title>Calloc problems</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167623#M718173</link>
      <description>i am doing an allocation of memory like that &lt;BR /&gt;: ptr = (char *) calloc (...,size) ;&lt;BR /&gt;when it done from main() everything is fine.&lt;BR /&gt;but if i call a sub function from the main ,&lt;BR /&gt;and allocate the pointer there , when i try to use the variable (ptr[0] = 'a')&lt;BR /&gt;i got segmentation fault.&lt;BR /&gt;as i mentioned before. it's only happen in a sub-function .&lt;BR /&gt;thanks for your help.&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Jan 2004 10:19:42 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167623#M718173</guid>
      <dc:creator>Alex Lavrov</dc:creator>
      <dc:date>2004-01-19T10:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calloc problems</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167624#M718174</link>
      <description>I suspect that it a case of the variable becoming undefined upon function exit. Calloc, malloc, ... work just fine inside functions. If you will post a section of your code that illusrates the problem then I suspect the fix will be trivial.&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Jan 2004 10:25:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167624#M718174</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2004-01-19T10:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calloc problems</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167625#M718175</link>
      <description>I hope you do not try:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;void myalloc( char *ptr )&lt;BR /&gt;{&lt;BR /&gt;ptr = malloc( 100 );&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;int main( void )&lt;BR /&gt;{&lt;BR /&gt;char *ptr;&lt;BR /&gt;myalloc( ptr );&lt;BR /&gt;ptr[ 0 ] = 0;&lt;BR /&gt;&lt;BR /&gt;return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Good luck&lt;BR /&gt;Adam&lt;BR /&gt;</description>
      <pubDate>Tue, 20 Jan 2004 14:07:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167625#M718175</guid>
      <dc:creator>Adam J Markiewicz</dc:creator>
      <dc:date>2004-01-20T14:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: Calloc problems</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167626#M718176</link>
      <description>You need to pass the address of ptr from main to the subfunction if you want the updated value back in main. Which also means you need to have the allocation sub-function take char **.</description>
      <pubDate>Tue, 20 Jan 2004 15:22:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167626#M718176</guid>
      <dc:creator>Don Morris_1</dc:creator>
      <dc:date>2004-01-20T15:22:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calloc problems</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167627#M718177</link>
      <description>Your other option is something like this:&lt;BR /&gt;&lt;BR /&gt;char *myfunc() {&lt;BR /&gt;    char *p;&lt;BR /&gt;&lt;BR /&gt;    p=(char *)calloc( size );&lt;BR /&gt;    &lt;BR /&gt;    /* Do some stuff with p */&lt;BR /&gt;&lt;BR /&gt;    return p;&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;int main() {&lt;BR /&gt;    char *p;&lt;BR /&gt;&lt;BR /&gt;    p = myfunc();&lt;BR /&gt;&lt;BR /&gt;    /* now you can access p */&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Hope this helps.</description>
      <pubDate>Fri, 30 Jan 2004 11:23:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/calloc-problems/m-p/3167627#M718177</guid>
      <dc:creator>Kenneth Platz</dc:creator>
      <dc:date>2004-01-30T11:23:45Z</dc:date>
    </item>
  </channel>
</rss>

