ringbuf/driver.c

41 lines
777 B
C
Raw Normal View History

2024-06-23 16:27:51 +02:00
/* SPDX-License-Identifier: MIT */
#include <stdlib.h>
#include <string.h>
2024-06-27 01:21:25 +02:00
#include <stdio.h>
2024-06-23 16:27:51 +02:00
#define rb_size_t size_t
#include "ringbuf.h"
2024-06-27 00:05:49 +02:00
int
main(void)
{
2024-06-23 16:27:51 +02:00
struct RingBuf rb;
rb_init(&rb, 10, malloc, sizeof(int));
2024-06-27 02:35:39 +02:00
int data[] = { 5, 6, 7, 8 };
2024-06-30 04:36:42 +02:00
printf("Address at data first element: %p\n", &data[0]);
printf("Address at internal first element: %p\n", &rb.buffer);
// rb_push(&rb, data, 4, memcpy);
rb_push_back(&rb, data, memcpy);
2024-06-27 14:06:08 +02:00
// Print addresses of data
2024-06-30 04:36:42 +02:00
for(int i = 0; i < 4; i++) {
2024-06-27 14:06:08 +02:00
printf("Address: %u\n", &data[i]);
}
print_seq(data, 4);
print_seq(rb.buffer, 4);
2024-06-23 16:27:51 +02:00
2024-06-27 01:21:25 +02:00
int dest[5];
2024-06-27 14:06:08 +02:00
// rb_read(&rb, (void *)dest, 5);
2024-06-27 01:21:25 +02:00
2024-06-27 14:06:08 +02:00
// for (int i = 0; i < 5; i++) {
// printf("Data: %d\n", dest[i]);
// }
2024-06-27 01:21:25 +02:00
rb_destroy(&rb, free);
2024-06-23 16:27:51 +02:00
return 0;
2024-06-27 00:05:49 +02:00
}