Visual C++ wrong entry point

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Laurent Schall

    Visual C++ wrong entry point

    I experience a problem where starting an application compiled with
    visual C++ 6 SP5 does not execute the function main(int argc, char
    **argv) and exit immediately with code 1 (0x1).

    Putting main as an entry point in the section Project -> settings ->
    link -> output -> entry-point symbol, makes the program calling main
    but my argc and argv arguments are both equal to 0.

    Has anyone an idea ?
  • John Harrison

    #2
    Re: Visual C++ wrong entry point


    "Laurent Schall" <schall_l@yahoo .fr> wrote in message
    news:a9847204.0 403031510.5922d 773@posting.goo gle.com...[color=blue]
    > I experience a problem where starting an application compiled with
    > visual C++ 6 SP5 does not execute the function main(int argc, char
    > **argv) and exit immediately with code 1 (0x1).
    >
    > Putting main as an entry point in the section Project -> settings ->
    > link -> output -> entry-point symbol, makes the program calling main
    > but my argc and argv arguments are both equal to 0.
    >
    > Has anyone an idea ?[/color]

    Maybe your program contains global objects whose constructors fail. Does
    this sound plausible?

    Setting the entry point under project settings sounds like a really bad
    idea, you were just messing with something you didn't understand.

    john


    Comment

    • Alf P. Steinbach

      #3
      Re: Visual C++ wrong entry point

      * schall_l@yahoo. fr (Laurent Schall) schriebt:[color=blue]
      >
      > I experience a problem where starting an application compiled with
      > visual C++ 6 SP5 does not execute the function main(int argc, char
      > **argv) and exit immediately with code 1 (0x1).[/color]

      As John Harrison responded, perhaps your program contains global objects
      whose constructors fail.

      Another possibility might be that you have used that compiler's non-standard
      feature where instead of 'main' a 'WinMain' or some such (there are actually
      several possibilities) is executed; in that case change the project settings
      or modify the compiler/linker arguments appropriately; see your documentation.

      [color=blue]
      > Putting main as an entry point in the section Project -> settings ->
      > link -> output -> entry-point symbol, makes the program calling main
      > but my argc and argv arguments are both equal to 0.
      >
      > Has anyone an idea?[/color]

      Yes, that is off-topic in this group, but in order to get you back on
      track: the entry point you specify to the linker, almost regardless of
      which C++ implementation, is _not_ the 'main' function, but some function
      in that C++ implementation' s runtime library that in turn calls 'main'.

      Comment

      • Julie

        #4
        Re: Visual C++ wrong entry point

        Laurent Schall wrote:[color=blue]
        >
        > I experience a problem where starting an application compiled with
        > visual C++ 6 SP5 does not execute the function main(int argc, char
        > **argv) and exit immediately with code 1 (0x1).
        >
        > Putting main as an entry point in the section Project -> settings ->
        > link -> output -> entry-point symbol, makes the program calling main
        > but my argc and argv arguments are both equal to 0.
        >
        > Has anyone an idea ?[/color]

        Main is defined as:

        int main(int argc, char * argv[])

        I don't know if that will solve your problem or not, but it is a start.

        Comment

        • Johannes Bauer

          #5
          Re: Visual C++ wrong entry point

          Julie wrote:[color=blue]
          > Main is defined as:
          >
          > int main(int argc, char * argv[])[/color]

          Which differs to Laurents definition (char** instead of char*[]) in what
          way?

          Johannes

          Comment

          • Julie

            #6
            Re: Visual C++ wrong entry point

            Johannes Bauer wrote:[color=blue]
            >
            > Julie wrote:[color=green]
            > > Main is defined as:
            > >
            > > int main(int argc, char * argv[])[/color]
            >
            > Which differs to Laurents definition (char** instead of char*[]) in what
            > way?
            >
            > Johannes[/color]

            Don't ask me -- ask the standards committee or refer to the current C++
            standard.

            I was simply trying to point out that the OP's implementation of main wasn't
            conformant to the standard. My guess is that it might be possible that when
            the compiler/linker is resolving the call to main, it doesn't resolve to the
            OP's implementation, and thus resulted in their reported problem ???

            Comment

            • Artie Gold

              #7
              Re: Visual C++ wrong entry point

              Julie wrote:[color=blue]
              > Johannes Bauer wrote:
              >[color=green]
              >>Julie wrote:
              >>[color=darkred]
              >>>Main is defined as:
              >>>
              >>>int main(int argc, char * argv[])[/color]
              >>
              >>Which differs to Laurents definition (char** instead of char*[]) in what
              >>way?
              >>
              >>Johannes[/color]
              >
              >
              > Don't ask me -- ask the standards committee or refer to the current C++
              > standard.
              >
              > I was simply trying to point out that the OP's implementation of main wasn't
              > conformant to the standard. My guess is that it might be possible that when
              > the compiler/linker is resolving the call to main, it doesn't resolve to the
              > OP's implementation, and thus resulted in their reported problem ???[/color]

              You miss the point.

              int main(int argc, char * argv[])

              and

              int main(int argc, char ** argv)

              Are totally equivalent signatures. Indistinguishab le to the compiler.

              HTH,
              --ag

              --
              Artie Gold -- Austin, Texas

              "Yeah. It's an urban legend. But it's a *great* urban legend!"

              Comment

              • Julie

                #8
                Re: Visual C++ wrong entry point

                Artie Gold wrote:[color=blue]
                > You miss the point.
                >
                > int main(int argc, char * argv[])
                >
                > and
                >
                > int main(int argc, char ** argv)
                >
                > Are totally equivalent signatures. Indistinguishab le to the compiler.[/color]

                I didn't miss the point.

                Where in the standard does it say that *var[] is equivalent to **var or that
                they mangle the same, or that main can be implemented w/ char **?

                Comment

                • Alf P. Steinbach

                  #9
                  Re: Visual C++ wrong entry point

                  * Julie <julie@aol.co m> schriebt:[color=blue]
                  >
                  > Where in the standard does it say that *var[] is equivalent to **var or that
                  > they mangle the same, or that main can be implemented w/ char **?[/color]

                  §8.3.5/3. This specifies what information is used to determine a function's
                  type (otherwise known as its signature), which all declarations of a given
                  function must agree on. First array parameters are changed to pointers. Then
                  cv-qualifiers such as 'const' are deleted. Then e.g. 'register' is deleted.
                  Then what you're left with is the function type.

                  And that means, if I'm not totally mistaken, that


                  int main( int const nArgs, char const * const * args )


                  is perfectly good -- actually a bit better, I'd suggest, than the example
                  given in the standard...

                  ;-)

                  Comment

                  • Mike Wahler

                    #10
                    Re: Visual C++ wrong entry point


                    "Julie" <julie@aol.co m> wrote in message news:4046B5AB.E BDF39FF@aol.com ...[color=blue]
                    > Artie Gold wrote:[color=green]
                    > > You miss the point.
                    > >
                    > > int main(int argc, char * argv[])
                    > >
                    > > and
                    > >
                    > > int main(int argc, char ** argv)
                    > >
                    > > Are totally equivalent signatures. Indistinguishab le to the compiler.[/color]
                    >
                    > I didn't miss the point.[/color]

                    I think you did.
                    [color=blue]
                    >
                    > Where in the standard does it say that *var[] is equivalent to **var or[/color]
                    that[color=blue]
                    > they mangle the same,[/color]

                    No 'mangling' is occurring.
                    [color=blue]
                    > or that main can be implemented w/ char **?[/color]

                    ISO/IEC 14882:1998(E)

                    [....]

                    8.3.5 Functions

                    [....]

                    3

                    [...]

                    The type of a function is determined using the following rules.
                    The type of each parameter is determined from its own decl­
                    specifier­seq and declarator. After determining the type of each
                    parameter, any parameter of type "array of T" or "function
                    returning T" is adjusted to be "pointer to T" or "pointer to
                    function returning T," respectively.

                    -Mike


                    Comment

                    • Rob Williscroft

                      #11
                      Re: Visual C++ wrong entry point

                      Alf P. Steinbach wrote in news:4046baf3.4 34241609@news.i ndividual.net:
                      [color=blue]
                      > * Julie <julie@aol.co m> schriebt:[color=green]
                      >>
                      >> Where in the standard does it say that *var[] is equivalent to **var
                      >> or that they mangle the same, or that main can be implemented w/ char
                      >> **?[/color]
                      >
                      > §8.3.5/3. This specifies what information is used to determine a
                      > function's type (otherwise known as its signature), which all
                      > declarations of a given function must agree on. First array
                      > parameters are changed to pointers. Then cv-qualifiers such as
                      > 'const' are deleted. Then e.g. 'register' is deleted. Then what
                      > you're left with is the function type.
                      >
                      > And that means, if I'm not totally mistaken, that
                      >
                      >
                      > int main( int const nArgs, char const * const * args )
                      >
                      >
                      > is perfectly good -- actually a bit better, I'd suggest, than the
                      > example given in the standard...
                      >
                      > ;-)
                      >[/color]

                      Are you sure, I read the standard as saying the cv-qualifier modifying
                      the paramiter type is removed, this is:

                      char * const -> char *, not
                      char const * -> char *.

                      In essence char * const and char * are different cv-qualifications of
                      the same type, where as char const * and char * are different types.

                      So int main( int const, char ** const ); is as much "const" as you
                      can legaly add to the usual int main( int, char ** );

                      Rob.
                      --

                      Comment

                      • Alf P. Steinbach

                        #12
                        Re: Visual C++ wrong entry point

                        * Rob Williscroft <rtw@freenet.RE MOVE.co.uk> schriebt:[color=blue]
                        > Alf P. Steinbach wrote in news:4046baf3.4 34241609@news.i ndividual.net:
                        >[color=green]
                        > > * Julie <julie@aol.co m> schriebt:[color=darkred]
                        > >>
                        > >> Where in the standard does it say that *var[] is equivalent to **var
                        > >> or that they mangle the same, or that main can be implemented w/ char
                        > >> **?[/color]
                        > >
                        > > §8.3.5/3. This specifies what information is used to determine a
                        > > function's type (otherwise known as its signature), which all
                        > > declarations of a given function must agree on. First array
                        > > parameters are changed to pointers. Then cv-qualifiers such as
                        > > 'const' are deleted. Then e.g. 'register' is deleted. Then what
                        > > you're left with is the function type.
                        > >
                        > > And that means, if I'm not totally mistaken, that
                        > >
                        > >
                        > > int main( int const nArgs, char const * const * args )
                        > >
                        > >
                        > > is perfectly good -- actually a bit better, I'd suggest, than the
                        > > example given in the standard...
                        > >
                        > > ;-)
                        > >[/color]
                        >
                        > Are you sure, I read the standard as saying the cv-qualifier modifying
                        > the paramiter type is removed, this is:
                        >
                        > char * const -> char *, not
                        > char const * -> char *.
                        >
                        > In essence char * const and char * are different cv-qualifications of
                        > the same type, where as char const * and char * are different types.
                        >
                        > So int main( int const, char ** const ); is as much "const" as you
                        > can legaly add to the usual int main( int, char ** );[/color]

                        Your interpretation seems much more reasonable and correct, yes.

                        After all it's logical that a const at the outermost level doesn't affect
                        what you can pass as actual arguments, whereas other const's will.

                        But I _like_ that version of 'main', I _want_ that version of 'main'... ;-)

                        --
                        A: Because it messes up the order in which people normally read text.
                        Q: Why is top-posting such a bad thing?
                        A: Top-posting.
                        Q: What is the most annoying thing on usenet and in e-mail?

                        Comment

                        • Default User

                          #13
                          Re: Visual C++ wrong entry point

                          Julie wrote:
                          [color=blue]
                          > Where in the standard does it say that *var[] is equivalent to **var or that
                          > they mangle the same, or that main can be implemented w/ char **?[/color]


                          The C standard helpfully adds a footnote for those who don't know that *
                          and [] are completely equivalent in function signatures:


                          8) Thus, int can be replaced by a typedef name defined as
                          int, or the type of argv can be written as char ** argv,
                          and so on.



                          Brian Rodenborn

                          Comment

                          • Julie

                            #14
                            Re: Visual C++ wrong entry point

                            Default User wrote:[color=blue]
                            >
                            > Julie wrote:
                            >[color=green]
                            > > Where in the standard does it say that *var[] is equivalent to **var or that
                            > > they mangle the same, or that main can be implemented w/ char **?[/color]
                            >
                            > The C standard helpfully adds a footnote for those who don't know that *
                            > and [] are completely equivalent in function signatures:
                            >
                            > 8) Thus, int can be replaced by a typedef name defined as
                            > int, or the type of argv can be written as char ** argv,
                            > and so on.
                            >
                            > Brian Rodenborn[/color]

                            I was not aware -- thanks to all that have pointed me in the right direction in
                            the standard.

                            I stand corrected, char ** argv to char * argv[] will most likely *not* solve
                            the OP's problem.

                            Comment

                            Working...