Skip to content

Instantly share code, notes, and snippets.

View pavly-gerges's full-sized avatar
🤖
Electrostat Lab.

Pavly Gerges (pavl_g) pavly-gerges

🤖
Electrostat Lab.
View GitHub Profile
@pavly-gerges
pavly-gerges / number_utils_max.c
Created February 13, 2023 15:52
Finds the maximum number among some numbers
#include <stdio.h>
/**
* Finds the maximum number between 2 numbers.
*
* @param n0 the first operand
* @param n1 the second operand
* @return the maximum number, any of the 2 numbers if the numbers are equal
*/
static inline int max0(int n0, int n1) {
@pavly-gerges
pavly-gerges / techdemo.c
Created January 30, 2023 18:49
Constant pointer to non-constant data
#include <stdio.h>
int main(void) {
int x = 8; // define x
int y; // define y
// constant location (pointer) to non-constant data
int* const ptr = &x;
// an attempt to modifiy the data will succeed
*ptr = 55;
printf("%d\n", x);
// an attempt to modify the memory location will fail
@pavly-gerges
pavly-gerges / techdemo.c
Created January 30, 2023 18:45
Constant pointer to constant data example
#include <stdio.h>
int main(void) {
int x = 8; // define x
int y; // define y
// constant pointer to constant data
const int* const ptr = &x;
printf("%d\n", x);
}
@pavly-gerges
pavly-gerges / jni-headers-example.c
Created January 27, 2023 22:40
An example for how java native interface defines its headers and the implementation of java native apis
#include <stdio.h>
#include <stdlib.h>
/**
* Headers
*/
struct JNINativeInterface_ {
void *reserved0;
void *reserved1;
void *reserved2;
@pavly-gerges
pavly-gerges / passing_params.c
Created January 26, 2023 22:09
Pass by reference V.S. Pass by address
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
static inline void printAddress(void** ptr_address) {
printf("%p\n", *ptr_address);
}
static inline void destroy(void** ptr_address) {
free(*ptr_address);
@pavly-gerges
pavly-gerges / realloc_example.c
Last active January 26, 2023 21:37
An example showing GNU `realloc`
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main() {
// allocating memory for 6 integers (total = 6 * 4 = 24 bytes)
int* ptr = malloc(6 * sizeof(int));
for (int i = 0; i < 6; i++) { /* 6 * 4 = 24 bytes = 24 * 8 = 192 bits */
@pavly-gerges
pavly-gerges / fastboot_help.md
Created January 25, 2023 21:42 — forked from MrHallows/fastboot_help.md
fastboot commands

Command:

$ fastboot help

Output:

usage: fastboot [OPTION...] COMMAND...

flashing:
@pavly-gerges
pavly-gerges / techdemo.c
Last active January 6, 2023 10:49
Test Deep copy V.S. Superficial copy
// Online C compiler to run C program online
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
typedef struct {
int baud;
uint8_t data;
} uart;
@pavly-gerges
pavly-gerges / HelloDynmaicArray.c
Created October 29, 2022 14:23
An example of dynamic arrays in C
/**
* @brief: Shows a minimalistic example of dynamic arrays.
*
* @author pavl_g.
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct {