Skip to content

Instantly share code, notes, and snippets.

View Silva97's full-sized avatar
🤔
Thinking, of course.

Luiz Felipe Silva Silva97

🤔
Thinking, of course.
View GitHub Profile
@Silva97
Silva97 / main.c
Created September 28, 2019 20:06
Exemplo para o artigo "Modularizando código em C"
// https://medium.com/@FreeDev/modularizando-c%C3%B3digo-em-c-784dc52d1c34
#include <stdio.h>
#include "module.h"
int main(void)
{
printf("Valor: %d\n", sum(3, 7));
return 0;
/********************
* Exemplo básico de uso de sockets no Linux.
* Por Luiz Felipe - https://github.com/Silva97
*
* Link do vídeo: https://youtu.be/GaxjJvMnz-I
********************/
#include <stdio.h>
#include <unistd.h>
@Silva97
Silva97 / target-example.c
Created November 2, 2021 11:28
Conditional function by target O.S. or architecture
#include <stdio.h>
#include "target.h"
OS_LINUX(char *os, void)
{
return "Linux";
}
OS_WINDOWS(char *os, void)
{
@Silva97
Silva97 / error_handling.c
Created October 21, 2021 20:40
PoC macros to do error handling in C
#include <stdio.h>
#include <string.h>
#define CATCH(name) \
if (0) \
_catch_##name:
#define FAIL(name) goto _catch_##name
#define FAIL_IF(expr, name) \
/********************
* Exemplo por Luiz Felipe.
* https://github.com/Silva97
********************/
#include <stdio.h>
#include <string.h>
#include <unistd.h> // Para usar chdir()
#include <dirent.h>
@Silva97
Silva97 / demo.c
Created August 19, 2021 16:35
C macro for print struct's fields
#include <stdio.h>
#include "printstruct.h"
typedef struct
{
int a;
char *b;
char c;
long int d;
long long int e;
@Silva97
Silva97 / get-function-size.c
Created July 11, 2021 15:45
Just an example of how to get the size of a function in bytes using the GCC compiler
// 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) \
funcname##_funcsize
/********************
* Exemplo básico de uso de sockets no Linux.
* Por Luiz Felipe - https://github.com/Silva97
*
* Link do vídeo: https://youtu.be/GaxjJvMnz-I
********************/
#include <stdio.h>
#include <winsock2.h>
@Silva97
Silva97 / box.c
Created March 6, 2021 00:30
Just an exercise example.
// 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)
{
#include <stdio.h>
int main(void)
{
int x = 5;
float y = 5.0f;
int *x_ptr = &x;
int *y_ptr = (int *)&y;