Further analysis of the use of the operators of s 1 en and s 2 en in C++ programming

  • 2020-05-07 20:12:02
  • OfStack

S operator s 1en s s 2en
C++11 introduces the alignof operator, which returns the alignment (in bytes) of the specified type. For maximum portability, use the alignof operator instead of the Microsoft-specific s/s 9en operator.
Returns a value of type size_t, which is the type alignment requirement.
grammar


    __alignof( 
  type 
)

note
Such as:

Expression
__alignof( char ) 1
__alignof( short ) 2
__alignof( int ) 4
__alignof( __int64 ) 8
__alignof( float ) 4
__alignof( double ) 8
__alignof( char* ) 4

S value is the same as that of the base type s sizeof. However, consider this example:


typedef struct { int a; double b; } S;
// __alignof(S) == 8

In this example, the s/s value is the alignment requirement for the largest element in the structure.
In the same way,


typedef __declspec(align(32)) struct { int a; } S;

S = 32 s = s = s
S use 1 as a parameter of a memory allocation routine. For example, given the structure S defined below, you can call a memory allocation routine named aligned_malloc to allocate memory on a particular alignment boundary.


typedef __declspec(align(32)) struct { int a; double b; } S;
int n = 50; // array size
S* p = (S*)aligned_malloc(n * sizeof(S), __alignof(S));


S 45en s 46en operator s 47en

Retrieves GUID and appends it to the expression.
grammar


   __uuidof (
  expression 
)

note
The expression can be a type name, a pointer, a reference, or an array of that type, a template of a particular type, or variables of those types. As long as the compiler can use it to find additional GUID, the argument is valid.
A special case of the inner function is when provided as an argument in 0 or NULL. In this case, s 59en will return GUID consisting of zeros.
Use this keyword to extract additional GUID:
1 object extends its properties with uuid.
Library blocks are created using module properties.
System_CAPS_note note
In the debug version, arbitration always initializes one object dynamically (at run time). With release, you can statically initialize the object (at compile time).
The following code (compiled using ole32.lib) displays 1 library block uuid for creating module properties:


// expre_uuidof.cpp
// compile with: ole32.lib
#include "stdio.h"
#include "windows.h"

[emitidl];
[module(name="MyLib")];
[export]
struct stuff {
  int i;
};

int main() {
  LPOLESTR lpolestr;
  StringFromCLSID(__uuidof(MyLib), &lpolestr);
  wprintf_s(L"%s", lpolestr);
  CoTaskMemFree(lpolestr);
}

annotation
When the library name is no longer within the scope, you can use s 82en _ instead of s 83en. Such as:


StringFromCLSID(__LIBID_, &lpolestr);


Related articles: