Last active
December 18, 2018 23:21
-
-
Save sphynx/becea49e70948f2bcaea87926708de46 to your computer and use it in GitHub Desktop.
Example of functions inside global structures, emulating "Serial" from Arduino language.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef void (*func) (const char *); | |
struct module { | |
func print; | |
func println; | |
}; | |
static void println(const char *str) | |
{ | |
puts(str); | |
} | |
static void print(const char *str) | |
{ | |
printf("%s", str); | |
} | |
static struct module Serial = { print, println }; | |
int main(void) | |
{ | |
Serial.print("hello, "); | |
Serial.print("world!"); | |
Serial.println(""); | |
Serial.println("exiting..."); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment