Giter VIP home page Giter VIP logo

Comments (8)

mmozeiko avatar mmozeiko commented on May 4, 2024 3

What I wanted to tell that just adding (c2h) is a wrong fix. It won't work, for example, for MSVC when compiling as C++ code: https://godbolt.org/g/VdV9Ek

For C code it is OK fix - both MSVC and GCC supports this kind of C99 initializer.

Proper way is to create a new temporary local variable or change C2_PLANE_AT to a function.

from cute_headers.

felselva avatar felselva commented on May 4, 2024

I checked the lines where C2_PLANE_AT is used and I found that you are using the macro to initialize structures (c2h). So, I think that just replacing:

#define C2_PLANE_AT( p, i ) { (p)->norms[ i ], c2Dot( (p)->norms[ i ], (p)->verts[ i ] ) }

with:

#define C2_PLANE_AT( p, i ) (c2h){ p->norms[ i ], c2Dot( p->norms[ i ], p->verts[ i ] ) }

Seems to solve the problem. Apparently, GCC needs to know that the braces "{...}" represent a c2h structure.

Edit: I sent a pull request (#21) with the change.

from cute_headers.

mmozeiko avatar mmozeiko commented on May 4, 2024

It works with MSVC because it enables C++1x by default. With GCC it works if you use C++11 (or newer) - -std=c++11

from cute_headers.

felselva avatar felselva commented on May 4, 2024

Probably works only with C++, then. I'm using C. I tried with both -std=c99 and -std=c11, but it didn't work. I found earlier that it would work with extensions, but that would not be ANSI/ISO and extensions aren't that widely used.

Platform: Linux
Compiler: GCC 6.3.1

from cute_headers.

mmozeiko avatar mmozeiko commented on May 4, 2024

Yes, with C this won't work unless it is used directly in initializer:

c2h t = C2_PLANE_AT(...);

This is not different from MSVC. It works there exactly the same as in GCC.

from cute_headers.

felselva avatar felselva commented on May 4, 2024

Yes, there's one case in particular that the macro isn't used for initialization:

c2h h = c2Mulxh( x, C2_PLANE_AT( p, i ) );

That's why adding the (c2h) fixed. The other cases are ok (all using for initialization).

from cute_headers.

felselva avatar felselva commented on May 4, 2024

Agreed. Changing C2_PLANE_AT to a function seems to be more reasonable to guarantee the library is cross-platform.

Edit:
I tried the following, as function:

c2h C2_PLANE_AT( const c2Poly* p, const int i )
{
	c2h h = { p->norms[ i ], c2Dot( (p)->norms[ i ], (p)->verts[ i ] ) };
	return h;
}

It worked here on Linux (GCC), and seems to work with MSVC, too (https://godbolt.org/g/3BeHdF). Confirmation needed.

from cute_headers.

RandyGaul avatar RandyGaul commented on May 4, 2024

Good change, thanks! I'll add you both as contributors.

from cute_headers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.