inline-code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephan Winter

    inline-code

    hi,

    i have a simple question for inline code :

    class x {
    private:
    int xx;
    public:
    int getXX(void){ return x; }
    };

    is the same like :

    class x {
    private:
    int xx;
    public:
    int getXX( void );
    };

    inline int x::getXX( void )
    {
    return x;
    }

    or is a differenz between these code ?

    thanks
    Stephan


  • Nils Petter Vaskinn

    #2
    Re: inline-code

    On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
    [color=blue]
    > hi,
    >
    > i have a simple question for inline code :
    >[/color]
    [color=blue]
    > int getXX(void){ return x; }[/color]
    [color=blue]
    > inline int x::getXX( void )[/color]
    [color=blue]
    > or is a differenz between these code ?[/color]

    There _may_ be a difference. The first kind of inlining is done when you
    compile the code #include-ing the header file. The second is a request to
    do inlining at the linking stage. Which it may or may not do.

    Read your compiler and linkers documentation.

    --
    NPV

    "the large print giveth, and the small print taketh away"
    Tom Waits - Step right up

    Comment

    • Martijn Lievaart

      #3
      Re: inline-code

      On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
      [color=blue]
      > hi,
      >
      > i have a simple question for inline code :[/color]

      [ snip inclass-definition and outclass-inline-definition ]
      [color=blue]
      > or is a differenz between these code ?[/color]

      No, they are equivalent.

      HTH,
      M4

      Comment

      • Howard

        #4
        Re: inline-code


        "Martijn Lievaart" <m@remove.this. part.rtij.nl> wrote in message
        news:pan.2004.0 1.19.15.32.06.1 36909@remove.th is.part.rtij.nl ...[color=blue]
        > On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
        >[color=green]
        > > hi,
        > >
        > > i have a simple question for inline code :[/color]
        >
        > [ snip inclass-definition and outclass-inline-definition ]
        >[color=green]
        > > or is a differenz between these code ?[/color]
        >
        > No, they are equivalent.
        >[/color]

        I don't think that's correct. As I understand it, the inline keyword is
        actually just a suggestion/request to inline the code. It's possible that
        the compiler/linker may *not* inline it. Isn't that correct?

        [color=blue]
        > HTH,
        > M4
        >[/color]


        Comment

        • Nick Hounsome

          #5
          Re: inline-code


          "Howard" <alicebt@hotmai l.com> wrote in message
          news:buh7iq$afo @dispatch.conce ntric.net...[color=blue]
          >
          > "Martijn Lievaart" <m@remove.this. part.rtij.nl> wrote in message
          > news:pan.2004.0 1.19.15.32.06.1 36909@remove.th is.part.rtij.nl ...[color=green]
          > > On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
          > >[color=darkred]
          > > > hi,
          > > >
          > > > i have a simple question for inline code :[/color]
          > >
          > > [ snip inclass-definition and outclass-inline-definition ]
          > >[color=darkred]
          > > > or is a differenz between these code ?[/color]
          > >
          > > No, they are equivalent.
          > >[/color]
          >
          > I don't think that's correct. As I understand it, the inline keyword is
          > actually just a suggestion/request to inline the code. It's possible that
          > the compiler/linker may *not* inline it. Isn't that correct?[/color]

          But that is true for either case.
          They are equivalent.
          [color=blue][color=green]
          > > HTH,
          > > M4
          > >[/color]
          >
          >[/color]


          Comment

          • Nick Hounsome

            #6
            Re: inline-code


            "Nils Petter Vaskinn" <no@spam.for.me .invalid> wrote in message
            news:pan.2004.0 1.19.15.25.37.1 85194@spam.for. me.invalid...[color=blue]
            > On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
            >[color=green]
            > > hi,
            > >
            > > i have a simple question for inline code :
            > >[/color]
            >[color=green]
            > > int getXX(void){ return x; }[/color]
            >[color=green]
            > > inline int x::getXX( void )[/color]
            >[color=green]
            > > or is a differenz between these code ?[/color]
            >
            > There _may_ be a difference. The first kind of inlining is done when you
            > compile the code #include-ing the header file. The second is a request to
            > do inlining at the linking stage. Which it may or may not do.
            >[/color]

            There isn't. And it isn't. But it is true that it mat not do the inlining.
            In particular the compiler is highly likely to inline nothing at all if you
            compile
            for debugging.

            (You may be getting confused with extern templates)
            [color=blue]
            > Read your compiler and linkers documentation.
            >
            > --
            > NPV
            >
            > "the large print giveth, and the small print taketh away"
            > Tom Waits - Step right up
            >[/color]


            Comment

            • Martijn Lievaart

              #7
              Re: inline-code

              On Mon, 19 Jan 2004 13:27:38 -0500, Howard wrote:
              [color=blue]
              >
              > "Martijn Lievaart" <m@remove.this. part.rtij.nl> wrote in message
              > news:pan.2004.0 1.19.15.32.06.1 36909@remove.th is.part.rtij.nl ...[color=green]
              >> On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
              >>[color=darkred]
              >> > hi,
              >> >
              >> > i have a simple question for inline code :[/color]
              >>
              >> [ snip inclass-definition and outclass-inline-definition ]
              >>[color=darkred]
              >> > or is a differenz between these code ?[/color]
              >>
              >> No, they are equivalent.
              >>[/color]
              >
              > I don't think that's correct. As I understand it, the inline keyword is
              > actually just a suggestion/request to inline the code. It's possible that
              > the compiler/linker may *not* inline it. Isn't that correct?[/color]

              That is right, but the same goes for the inclass definition, so they are
              equivalent. (BTW I've yet to see a linker that can do inlining, although
              it makes sense).

              M4


              Comment

              • Andrey Tarasevich

                #8
                Re: inline-code

                Howard wrote:
                [color=blue]
                > "Martijn Lievaart" <m@remove.this. part.rtij.nl> wrote in message
                > news:pan.2004.0 1.19.15.32.06.1 36909@remove.th is.part.rtij.nl ...[color=green]
                >> On Mon, 19 Jan 2004 16:23:48 +0100, Stephan Winter wrote:
                >>[color=darkred]
                >> > hi,
                >> >
                >> > i have a simple question for inline code :[/color]
                >>
                >> [ snip inclass-definition and outclass-inline-definition ]
                >>[color=darkred]
                >> > or is a differenz between these code ?[/color]
                >>
                >> No, they are equivalent.
                >>[/color]
                >
                > I don't think that's correct. As I understand it, the inline keyword is
                > actually just a suggestion/request to inline the code. It's possible that
                > the compiler/linker may *not* inline it. Isn't that correct?
                > ...[/color]

                Inlining is always a suggestion regardless of how the function is
                declared - outside the class definition with explicit 'inline' keyword
                or inside the class definition. Both variants are indeed equivalent.

                --
                Best regards,
                Andrey Tarasevich

                Comment

                • Howard

                  #9
                  Re: inline-code


                  "Andrey Tarasevich" <andreytarasevi ch@hotmail.com> wrote in message
                  news:100onhtokh och8d@news.supe rnews.com...[color=blue]
                  >
                  > Inlining is always a suggestion regardless of how the function is
                  > declared - outside the class definition with explicit 'inline' keyword
                  > or inside the class definition. Both variants are indeed equivalent.
                  >
                  > --
                  > Best regards,
                  > Andrey Tarasevich
                  >[/color]

                  Ok, thanks. I learn something new here every day! :-)

                  -Howard


                  Comment

                  • Chris Theis

                    #10
                    Re: inline-code


                    "Martijn Lievaart" <m@remove.this. part.rtij.nl> wrote in message
                    news:pan.2004.0 1.19.20.28.21.8 35068@remove.th is.part.rtij.nl ...
                    [SNIP][color=blue][color=green]
                    > > I don't think that's correct. As I understand it, the inline keyword is
                    > > actually just a suggestion/request to inline the code. It's possible[/color][/color]
                    that[color=blue][color=green]
                    > > the compiler/linker may *not* inline it. Isn't that correct?[/color]
                    >
                    > That is right, but the same goes for the inclass definition, so they are
                    > equivalent. (BTW I've yet to see a linker that can do inlining, although
                    > it makes sense).
                    >
                    > M4[/color]

                    AFAIK SGI's and IBM's Visual Age compiler are/were able to do such things.
                    Furthermore there are some other inhouse compilers that can do that job,
                    although it is still not very common.

                    Chris


                    Comment

                    • Andrey Tarasevich

                      #11
                      Re: inline-code

                      Chris Theis wrote:[color=blue][color=green][color=darkred]
                      >> > I don't think that's correct. As I understand it, the inline keyword is
                      >> > actually just a suggestion/request to inline the code. It's possible[/color][/color]
                      > that[color=green][color=darkred]
                      >> > the compiler/linker may *not* inline it. Isn't that correct?[/color]
                      >>
                      >> That is right, but the same goes for the inclass definition, so they are
                      >> equivalent. (BTW I've yet to see a linker that can do inlining, although
                      >> it makes sense).
                      >>
                      >> M4[/color]
                      >
                      > AFAIK SGI's and IBM's Visual Age compiler are/were able to do such things.
                      > Furthermore there are some other inhouse compilers that can do that job,
                      > although it is still not very common.
                      > ...[/color]

                      This capability is not really needed for standard C++ inlining (as it is
                      defined in C++ language specification), since the language specification
                      requires source code of inline function to be available in every
                      translation unit where the function is used.

                      --
                      Best regards,
                      Andrey Tarasevich

                      Comment

                      Working...