#305 GCC doesnt allow structures passed by value?

Known_bugs
closed
gcc (462)
2003-03-12
2003-03-02
No

I find this odd, I just downloaded the latest Bloodshed
Dev C++ for windows, and immediately noticed that my
projects wont compile because I pass structures by
value. I know it isn't a "suggested" technique, but it is
allowed in C++, in fact, Bjarne Stoustrup does it a lot in
his C++ book. Maybe I have a compiler setting wrong,
but Im sure I should be able to do this without getting
compiler errors.

66 C:\Documents and Settings\Rob
Stoddard\Desktop\mapreader\common\3DMath.cpp
could not convert `Face::planew(float*)(xfrm)' to `Plane&

In that instance, Face::planew(float* xfrm) returns a
Plane (the whole structure, returned by value, which
should also be done). I try doing any passing or
returning of structures by value, the compiler errors.

Discussion

  • Danny Smith

    Danny Smith - 2003-03-02

    Logged In: YES
    user_id=11494

    A testcase would be nice, as would details on the
    compiler version you are talking about

    MS convention is to allow pass and return of small
    structures (<=8 bytes) by value. GCC for mingw tries to
    follow that convention. The aggregate return part has
    just been fixed recently but I think the patch made it
    into gcc-3.2.2-200302080-1 distributed at mingw file
    download page (in Release Candidate section)

    Danny

     
  • Rob Stoddard

    Rob Stoddard - 2003-03-04

    Logged In: YES
    user_id=569184

    OK, I'll give a standard case in the programming I am doing.
    struct Plane
    { // a plane is Ax +By +Cz + D = 0
    float A, B, C, D;
    Plane Transform(float xfrm[16]); // should return the plane,
    // transformed by the matrix stored in xfrm
    };

    Plane Plane::Transform(float xfrm[16]) is actually the function
    planew(float* ) that I mention above. It should pass a Plane,
    by value in its return statement. I have been using this quite
    successfully in MSVC++, and I don't see any problems with
    doing this IAW Bjarne Stoustrup's book. I've always been
    worried about "MS convention" because Microsoft has been
    known to mutilate or totally rewrite standards.

     
  • Luke Dunstan

    Luke Dunstan - 2003-03-05
    • status: open --> pending
     
  • Luke Dunstan

    Luke Dunstan - 2003-03-05

    Logged In: YES
    user_id=30442

    That code compiles fine, but the above error doesn't look like
    it is in the header so you'll have to show the function definition
    and the function call. Ideally it would be in the form of a small
    self-contained piece of code so that we can actually try
    compiling it.

     
  • Danny Smith

    Danny Smith - 2003-03-05

    Logged In: YES
    user_id=11494

    I can't see the bug either. This compiles without error
    Danny

    / foo.C */
    struct Plane
    {
    float A, B, C, D;
    Plane Transform(float xfrm[16]);
    };

    extern float* tfrm;

    Plane foo(Plane z)
    {
    return z.Transform(tfrm);
    }

     
  • Danny Smith

    Danny Smith - 2003-03-05
    • status: pending --> open
     
  • Rob Stoddard

    Rob Stoddard - 2003-03-05

    Logged In: YES
    user_id=569184

    Aha, I figured out what it is thats bugging my compiles.
    MinGW does not allow a by value passed return from a
    function to a function that takes a refrence. IMHO, I am at
    fault here, I shouldnt be doing that in the first place.

     
  • Danny Smith

    Danny Smith - 2003-03-12
    • status: open --> closed
     
  • Danny Smith

    Danny Smith - 2003-03-12

    Logged In: YES
    user_id=11494

    Closed. Submitter reports that error was in user code.
    Danny

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks