当前位置:网站首页>assert _ Aligns

assert _ Aligns

2022-07-26 02:29:00 Virgo programmer's friend

macro assert The definition of depends on the standard library and does not define another macro NDEBUG.

if NDEBUG It contains <assert.h> The point in the source code of is defined as macro name , be assert Not doing anything .

If not defined NDEBUG, be assert Set its parameters ( Must have scalar type ) Equal to zero comparison , If equal , be assert Output the specified diagnostic information on the standard error output , And call abort. Diagnostic information requires text containing expressions , And standard macros _FILE_、_LINE_ And predefined variables _func_ Value .

Parameters

condition -- Scalar type expression

Return value

( nothing )

Example :

#include<stdio.h>

#include<assert.h>

#include<math.h>

int main(void)

{

double x = -1.0;

assert(x>=0.0);

printf("sqrt(x) = %f\n",sqrt(x));

return 0;

}

_Aligns

Appears in declarative syntax , As a specifier for modifying the alignment requirements of declaration objects .

expression : Any integer constant expression whose value is legally aligned or zero .

type : Any type name

_Aligns You can only declare that it is not a bit field , And does not have a register storage class . It cannot be used for function parameter declarations , Not for typedef. When used for declaration . Set the alignment requirements of the declared object to :

1) Result of expression , Unless it is zero .

2) Alignment requirements for types , It is set to _Alignof(type)

Example :

#include<stdalign.h>

#include<stdio.h>

// every last struct sse_t Objects of type will be in 16 Byte boundary alignment .

struct sse_t

{

aligns(16) float sse_data[4];

};

// such struct data Every object of will be in 128 Byte boundary alignment

struct data{

char x;

alignas(128) char cacheline[128]; // Over aligned char Array objects ;

};

int main(void)

{

alignas(2048) struct data d; // this struct data Instances of will be more strictly aligned ;

}

Storage class specifier

auto - Automatic storage period and no link

register- Automatic storage with no links , You can't take the address of this object

static Static storage and internal links ( Unless this scope )

extern- Static storage period and external link

Static storage period : Storage is the execution process of the whole program .

原网站

版权声明
本文为[Virgo programmer's friend]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/207/202207260222416822.html