0

Hello I'm doing a MASM course and there is also C++ but the teacher is using Visual Studio and I'm using Linux. In the code I'm doing there is the following instructions:

__declspec(align(#))

I have this code:

_desclspec(align(16))XmmVal a;
_desclspec(align(16))XmmVal b;
_desclspec(align(16))XmmVal c[2];

But I cannot use "align" and "_desclspec" on linux by compiling with "i686-w64-mingw32-g++" because I get an error "was not declared in this scope":

SSEPackedIntegerArithmetic.cpp:24:16: error: ‘align’ was not declared in this scope 24 | _desclspec(align(16))XmmVal a; | ^~~~~ SSEPackedIntegerArithmetic.cpp:24:5: error: ‘_desclspec’ was not declared in this scope 24 |
_desclspec(align(16))XmmVal a; | ^~~~~~~~~~

How can I solve this problem? Thank you!

Z3R0
  • 1,011
  • 10
  • 19
  • https://stackoverflow.com/questions/7895869/cross-platform-alignx-macro – 273K Jun 22 '22 at 02:51
  • Thanks really much ! But I still get the same error :/ – Z3R0 Jun 22 '22 at 02:54
  • 2
    I wouldn't bother with the linked answer. As of C++11 and VS2015 [you should be using](https://learn.microsoft.com/en-us/cpp/cpp/alignment-cpp-declarations?view=msvc-170) the standard `alignas` instead of the Microsoft specific `__declspec(align)`. They are equivalent. – HTNW Jun 22 '22 at 02:57
  • @HTNW Thank you so "alignas(16) XmmVal" a for example? – Z3R0 Jun 22 '22 at 03:00

1 Answers1

2

The issue isn't "Windows vs. Linux" as much as "choice of compiler".

Here's the documentation for MSVC. Note the caveat about "MSVS 2015 and later":

https://learn.microsoft.com/en-us/cpp/cpp/align-cpp

In Visual Studio 2015 and later, use the C++11 standard alignas specifier to control alignment. For more information, see Alignment.

The equivalent to _declspec(align(16)) for gcc would be:

https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html

__attribute__((aligned (16)))

You should definitely see if your compiler supports alignas.

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • I am using "i686-w64-mingw32-g++" because I need to compile with MASM Assembly code – Z3R0 Jun 22 '22 at 02:58