Files
damus/nostrdb/ccan/ccan/alignof/_info
Rusty Russell a8d7d971b1 nostrdb: ccan: sync with normal versions.
This is the version of CCAN which CLN was using at the time these
were taken.  Unfortunately lots of whitespace has been changed,
but AFAICT no source changes.

Here's the command I ran (with ../ccan checked out to 1ae4c432):

```
make update-ccan CCAN_NEW="alignof array_size build_assert check_type container_of cppmagic likely list mem short_types str structeq take tal tal/str typesafe_cb utf8 endian crypto/sha256"
```

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: William Casarin <jb55@jb55.com>
2025-08-11 16:40:00 -07:00

52 lines
1.3 KiB
Plaintext

#include "config.h"
#include <stdio.h>
#include <string.h>
/**
* alignof - ALIGNOF() macro to determine alignment of a type.
*
* Many platforms have requirements that certain types must be aligned
* to certain address boundaries, such as ints needing to be on 4-byte
* boundaries. Attempting to access variables with incorrect
* alignment may cause performance loss or even program failure (eg. a
* bus signal).
*
* There are times which it's useful to be able to programatically
* access these requirements, such as for dynamic allocators.
*
* Example:
* #include <stdio.h>
* #include <stdlib.h>
* #include <ccan/alignof/alignof.h>
*
* // Output contains "ALIGNOF(char) == 1"
* // Will also print out whether an onstack char array can hold a long.
* int main(void)
* {
* char arr[sizeof(int)];
*
* printf("ALIGNOF(char) == %zu\n", ALIGNOF(char));
* if ((unsigned long)arr % ALIGNOF(int)) {
* printf("arr %p CANNOT hold an int\n", arr);
* exit(1);
* } else {
* printf("arr %p CAN hold an int\n", arr);
* exit(0);
* }
* }
*
* License: CC0 (Public domain)
* Author: Rusty Russell <rusty@rustcorp.com.au>
*/
int main(int argc, char *argv[])
{
if (argc != 2)
return 1;
if (strcmp(argv[1], "depends") == 0) {
return 0;
}
return 1;
}