Skip to content

Instantly share code, notes, and snippets.


Luiz Felipe Silva97

View GitHub Profile
Silva97 / target-example.c
Created Nov 2, 2021
Conditional function by target O.S. or architecture
View target-example.c
#include <stdio.h>
#include "target.h"
OS_LINUX(char *os, void)
return "Linux";
OS_WINDOWS(char *os, void)
Silva97 / error_handling.c
Created Oct 21, 2021
PoC macros to do error handling in C
View error_handling.c
#include <stdio.h>
#include <string.h>
#define CATCH(name) \
if (0) \
#define FAIL(name) goto _catch_##name
#define FAIL_IF(expr, name) \
Silva97 / lexer-example.c
Last active Sep 15, 2021
Example of lexical analysis in C language.
View lexer-example.c
* Example by Luiz Felipe (Silva97)
* It's just an example. Don't consider it a final code and DON'T write
* all your code on a unique module, please.
* Tip: Use a struct to manipulate translate units instead of use only a
* FILE pointer ;)
Silva97 / demo.c
Created Aug 19, 2021
C macro for print struct's fields
View demo.c
#include <stdio.h>
#include "printstruct.h"
typedef struct
int a;
char *b;
char c;
long int d;
long long int e;
Silva97 / get-function-size.c
Created Jul 11, 2021
Just an example of how to get the size of a function in bytes using the GCC compiler
View get-function-size.c
// See how it's works using: gcc -S get-function-size.c -o get-function-size.s
// To manually check function size: objdump -d get-function-size
#include <stdio.h>
#define DECLARE_FUNCSIZE(funcname) \
extern unsigned int funcname##_funcsize; \
asm(#funcname "_funcsize: .long . - " #funcname "\n\t")
#define FUNCSIZE(funcname) \
Silva97 / box.c
Created Mar 6, 2021
Just an exercise example.
View box.c
// Just an exercise example.
#include <stdio.h>
#include <stdlib.h>
void crep(int character, unsigned int number);
int main(int argc, char **argv)
if (argc < 2)
View c-typing-example.c
#include <stdio.h>
int main(void)
int x = 5;
float y = 5.0f;
int *x_ptr = &x;
int *y_ptr = (int *)&y;
Silva97 / Sum - Silva97.yaml
Created Oct 24, 2020
Turing Machine code for sum numbers | Just a test :)
View Sum - Silva97.yaml
name: Sum - Silva97
source code: |-
input: '0010+0011'
blank: ' '
start state: look
0: {L: left3}
1: {L: left3}
'+': {L: left3}
View substr.c
#include <stdio.h>
// Example of code in C to get substrings
char *substr(char *dest, char *src, int start, int end)
char *start_address = dest;
for (src = src + start; *src && end > 0; dest++, src++, end--) {
*dest = *src;
Silva97 / benchmark_smaller_branchless.c
Created Jul 8, 2020
Teste de benchmark de um exemplo de código branchless para verificar qual número é menor
View benchmark_smaller_branchless.c
#include <stdio.h>
#include <stdlib.h>
#include "metric.h" //
int smaller(int a, int b)
if (a < b) {
return a;