Alignment of function parameters

Alignment of function parameters

Hi. I've been posting quite a bit here lately so I hope I'm not getting on anyone's nerves. Just trying to understand Havok as best as I can :).

I have a

struct Hit
hkVector4 position;
//other non-hk variables

and a static function

static bool HitCompare( Hit firstHit, Hit secondHit )

When I try to compile, I get

error C2719: 'firstHit': formal parameter with __declspec(align('16')) won't be aligned

as an error in visual studio. I have looked up this error and Microsoft says that I cannot align my function parameters with __declspec. However, I am not using this function in my code at all, so I think it must be part of Havok's memory management system. Is there any way to turn off the alignment on this function or get rid of this error? I can bend my code to fix the bug but I'm afraid there is probably a deeper issue here, as this means I can't use any static functions in my code I'm guessing.

As a note, I have tried passing the struct as a reference parameter, and still get the same error. Help?

Edit: It seems that I am also getting the error by calling a non-static version of my function within a class of mine that inherits from hkReferencedObject. Just need a way to turn off the alignment or something I think...

6 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Hi fiction:

VS compile has problem to alignment the function parameter.

But, pass in a whole structure is not a good idea. Because the compile will copy the whole structure on stack when calling the function. So you should try to pass in a reference or pointer.

For example
static bool HitCompare( Hit& firstHit, Hit& secondHit )
And maybe you should use "const" if you do not want to change the value.

Also, you should not try to disable those warning otherwise you will probably get some inaccurate values from the parameter.


Developer Support Engineer

I noted in the original post that it happens with the references as well. It simply won't let me use a static function in the cases I gave. What can I do to be able to use my static function again?

Hmmm, it should not have any difference between using static and not using static. It sounds weird for me.

Can you test compile
static bool HitCompare( hkVector4& firstHit, hkVector4& secondHit )

Do you have your own "Struct Member Alignment" setting? Would you mind post your code and I can test for you?

Developer Support Engineer

Hmm....I just tried it again and I seem to be able to use it as long as I use references. I was quite sure that I had tested it before and it was not working with static functions, but I guess I was mistaken. I know that I am supposed to be passing references to most functions and typically do, but just for this case is there any way to pass in the struct without a reference and without the alignment? I have no custom alignment code.

As long as there is an aligned element in the struct like hkVector4, compiler will definitely try to align it when creating copies on the stack, which will be failed in current VS. You can pass in pointers if you want. Or, copy out all data in hkVector4 and save it in float[4].....

Sorry , I do not know there is any settings or define to disable those error check.

Developer Support Engineer

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi