Jump to content

GNU C++ Alignment With Initializer List Possible?

patrickjp93

Is it possible to do what this code SHOULD do?

 

float velocities[8] __attribute__ ((aligned (__BIGGEST_ALIGNMENT__))) = { something, something, ...};

 

Note, I have tried all 3 available positiona for the attribute. None of them work, but I can't find anywhere in the gnu documentation that says you shouldn't be able to do this.

 

It would be incredibly wasteful to fill each element with preset values one after the other.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
Share on other sites

Link to post
Share on other sites

33 minutes ago, AlexTheRose said:

If you’re using C++11/14/1y/1z/1xyzzy, it should be doable. IIRC they added in static array declaration + initialisation for most all things in recent versions of ISO C++. Hell, you should be able to do jagged arrays and initialise hashmaps and all kinds of stuff. Not positive on everything though, but I’m fairly certain you can do that.

If you can find an example or provide one with perhaps my missing compiler flag, that would be great, because I'm coming up blank around the net.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
Share on other sites

Link to post
Share on other sites

18 minutes ago, AlexTheRose said:

Someone pointed me to the alignas keyword… have you thought of using that? It may solve your delimma, and a lot more elegantly than __attribute__ abhorrences.

Thanks a bunch! That did the trick.

Software Engineer for Suncorp (Australia), Computer Tech Enthusiast, Miami University Graduate, Nerd

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×