File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * @file generate_cube.c
3+ * @author Xuhua Huang
4+ * @brief
5+ * @version 0.1
6+ * @date 2025-06-08
7+ *
8+ * @copyright Copyright (c) 2025
9+ *
10+ */
11+
12+ #include <stdint.h>
13+ #include <stdio.h>
14+ #include <stdlib.h>
15+
16+ typedef uint32_t (* lut_func_t )(uint32_t );
17+
18+ // Function to generate a LUT dynamically
19+ uint32_t * generate_lut (size_t size , lut_func_t func ) {
20+ uint32_t * table = malloc (size * sizeof (uint32_t ));
21+ if (table == NULL ) {
22+ return NULL ;
23+ }
24+
25+ for (size_t i = 0 ; i < size ; ++ i ) {
26+ table [i ] = func (i );
27+ }
28+ return table ;
29+ }
30+
31+ // Example transformation function
32+ uint32_t cube (uint32_t x ) {
33+ return x * x * x ;
34+ }
35+
36+ int main (void ) {
37+ size_t size = 10 ;
38+ uint32_t * cube_table = generate_lut (size , cube );
39+
40+ if (cube_table ) {
41+ for (size_t i = 0 ; i < size ; ++ i ) {
42+ printf ("Cube of %zu is %u\n" , i , cube_table [i ]);
43+ }
44+ free (cube_table );
45+ }
46+
47+ return 0 ;
48+ }
You can’t perform that action at this time.
0 commit comments