File: postgres_struct_func1.c

package info (click to toggle)
chibicc 1.0.23.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,832 kB
  • sloc: ansic: 62,911; sh: 275; makefile: 92
file content (24 lines) | stat: -rw-r--r-- 523 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

#include <string.h>
#include "test.h"

struct MyStruct {
    void (*myFunc)(void *, const void *, size_t);
};

// Initialize the struct with memcpy assigned to the function pointer
struct MyStruct myStruct = {
    .myFunc = memcpy
};

int main() {
    // Use the function pointer
    char src[20] = "Hello, World!";
    char dest[20];
    myStruct.myFunc(dest, src, strlen(src) + 1);

    printf("Copied string: %s\n", dest);  // Should print: "Copied string: Hello, World!"
    ASSERT(13, strlen(dest));

    return 0;
}