<?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: main function not executed in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093074#M717337</link>
    <description>Thank you all who responded,&lt;BR /&gt;&lt;BR /&gt;The problem was the main() is in C while the&lt;BR /&gt;rest of the code is in C++.  I followed all&lt;BR /&gt;the recommendations of mixing C and C++&lt;BR /&gt;objects, and this was working before I&lt;BR /&gt;upgraded to Oracle9i (I guess one of the&lt;BR /&gt;patches needed by oracle caused this&lt;BR /&gt;problem).  Before I had to called _main()&lt;BR /&gt;in order to create all static objects and I&lt;BR /&gt;had control where in the code I called &lt;BR /&gt;_main(), but now I gues HP decided that an&lt;BR /&gt;explicit call to _main() was not necessary&lt;BR /&gt;anymore, so all the creation of static&lt;BR /&gt;objects is done automatically as it should&lt;BR /&gt;be.&lt;BR /&gt;Here is a small example:&lt;BR /&gt;&lt;BR /&gt;file main.c:&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;    /* Initializing communications */&lt;BR /&gt;    ...&lt;BR /&gt;    /* call app */&lt;BR /&gt;    func1();&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;file Obj1.C:&lt;BR /&gt;/* Globals */&lt;BR /&gt;Object1 *obj1 = new Object1();&lt;BR /&gt;&lt;BR /&gt;void func1()&lt;BR /&gt;{&lt;BR /&gt;    ...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;As this example shows the object 'obj1' is&lt;BR /&gt;created before even calling main() because&lt;BR /&gt;it is a global object.  In my application,&lt;BR /&gt;the problem was that the constructor of&lt;BR /&gt;'Object1' tries to communicate to oracle&lt;BR /&gt;and the main application, but the&lt;BR /&gt;communication is initialized in main().&lt;BR /&gt;&lt;BR /&gt;In order for this to work properly I changed&lt;BR /&gt;the file 'Obj1.C' to:&lt;BR /&gt;/* Globals */&lt;BR /&gt;Object1 *obj1;&lt;BR /&gt;&lt;BR /&gt;void func1()&lt;BR /&gt;{&lt;BR /&gt;    /* Create global objects */&lt;BR /&gt;    obj1 = new Object1();&lt;BR /&gt;    ...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Now 'obj1' is created when calling func1(),&lt;BR /&gt;right after main() already initialized&lt;BR /&gt;communications with the main application.&lt;BR /&gt;&lt;BR /&gt;Hope I was able to explain all of this well.&lt;BR /&gt;&lt;BR /&gt;Thanks again for the all the help I got.&lt;BR /&gt;</description>
    <pubDate>Wed, 15 Oct 2003 11:17:37 GMT</pubDate>
    <dc:creator>Jorge Mora</dc:creator>
    <dc:date>2003-10-15T11:17:37Z</dc:date>
    <item>
      <title>main function not executed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093070#M717333</link>
      <description>Hello,&lt;BR /&gt;I compile a program with aCC, but when it runs&lt;BR /&gt;it skips the main() completely: I put a print&lt;BR /&gt;statement at the very beginning of the main()&lt;BR /&gt;function but when I execute the program the &lt;BR /&gt;print statement is never called as all other&lt;BR /&gt;initializations and it looks like starts running some other piece of code which shouldn't be running unless interaction with&lt;BR /&gt;the user.&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Oct 2003 13:06:08 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093070#M717333</guid>
      <dc:creator>Jorge Mora</dc:creator>
      <dc:date>2003-10-14T13:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: main function not executed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093071#M717334</link>
      <description>Just in case this is the post that doesn't get removed, I posted this in your other thread.&lt;BR /&gt;&lt;BR /&gt;This can not behappening. What probably is happening is that you have done your printf but not flushed standard output yet with "fflush()" or even "\n" which might explain why you can't see it.&lt;BR /&gt;&lt;BR /&gt;Can I suggest you post the code snippet so we can have a look.</description>
      <pubDate>Tue, 14 Oct 2003 13:07:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093071#M717334</guid>
      <dc:creator>Mark Grant</dc:creator>
      <dc:date>2003-10-14T13:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: main function not executed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093072#M717335</link>
      <description>main() function is always executed.&lt;BR /&gt;There may be nothing to print (check arguments of 'print' statement), the statement itself can be skipped in the flow of the program, standard output can be redirected, but main() has to be executed.</description>
      <pubDate>Tue, 14 Oct 2003 13:12:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093072#M717335</guid>
      <dc:creator>Vitek Pepas</dc:creator>
      <dc:date>2003-10-14T13:12:27Z</dc:date>
    </item>
    <item>
      <title>Re: main function not executed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093073#M717336</link>
      <description>My best guess is that some of the library functions were written in C++. There are some special rules for mixing C and C++ and one of those is that the main() should be written in C++. Try changing your main to C++ and see if you now see your fprintf's. There are some rules for using a main written in C and linking with C++; see the otherlangs.html file that is part of the aCC on-line documentation.&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Oct 2003 13:24:34 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093073#M717336</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-10-14T13:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: main function not executed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093074#M717337</link>
      <description>Thank you all who responded,&lt;BR /&gt;&lt;BR /&gt;The problem was the main() is in C while the&lt;BR /&gt;rest of the code is in C++.  I followed all&lt;BR /&gt;the recommendations of mixing C and C++&lt;BR /&gt;objects, and this was working before I&lt;BR /&gt;upgraded to Oracle9i (I guess one of the&lt;BR /&gt;patches needed by oracle caused this&lt;BR /&gt;problem).  Before I had to called _main()&lt;BR /&gt;in order to create all static objects and I&lt;BR /&gt;had control where in the code I called &lt;BR /&gt;_main(), but now I gues HP decided that an&lt;BR /&gt;explicit call to _main() was not necessary&lt;BR /&gt;anymore, so all the creation of static&lt;BR /&gt;objects is done automatically as it should&lt;BR /&gt;be.&lt;BR /&gt;Here is a small example:&lt;BR /&gt;&lt;BR /&gt;file main.c:&lt;BR /&gt;int main()&lt;BR /&gt;{&lt;BR /&gt;    /* Initializing communications */&lt;BR /&gt;    ...&lt;BR /&gt;    /* call app */&lt;BR /&gt;    func1();&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;file Obj1.C:&lt;BR /&gt;/* Globals */&lt;BR /&gt;Object1 *obj1 = new Object1();&lt;BR /&gt;&lt;BR /&gt;void func1()&lt;BR /&gt;{&lt;BR /&gt;    ...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;As this example shows the object 'obj1' is&lt;BR /&gt;created before even calling main() because&lt;BR /&gt;it is a global object.  In my application,&lt;BR /&gt;the problem was that the constructor of&lt;BR /&gt;'Object1' tries to communicate to oracle&lt;BR /&gt;and the main application, but the&lt;BR /&gt;communication is initialized in main().&lt;BR /&gt;&lt;BR /&gt;In order for this to work properly I changed&lt;BR /&gt;the file 'Obj1.C' to:&lt;BR /&gt;/* Globals */&lt;BR /&gt;Object1 *obj1;&lt;BR /&gt;&lt;BR /&gt;void func1()&lt;BR /&gt;{&lt;BR /&gt;    /* Create global objects */&lt;BR /&gt;    obj1 = new Object1();&lt;BR /&gt;    ...&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;Now 'obj1' is created when calling func1(),&lt;BR /&gt;right after main() already initialized&lt;BR /&gt;communications with the main application.&lt;BR /&gt;&lt;BR /&gt;Hope I was able to explain all of this well.&lt;BR /&gt;&lt;BR /&gt;Thanks again for the all the help I got.&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Oct 2003 11:17:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093074#M717337</guid>
      <dc:creator>Jorge Mora</dc:creator>
      <dc:date>2003-10-15T11:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: main function not executed</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093075#M717338</link>
      <description>Good. That was why I suggested that you convert your baby test program to C++ and link it with your libraries. That would have instantly revealed the problem. I was rather sure that this was your problem and if you are not aware of how linking with global objects work, it can send you down really crazy paths.&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Oct 2003 12:03:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/main-function-not-executed/m-p/3093075#M717338</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2003-10-15T12:03:32Z</dc:date>
    </item>
  </channel>
</rss>

