Skip to content

Instantly share code, notes, and snippets.

union swap_byte {
void swap();
void set_byte(unsigned short i);
void show_word();
unsigned short u;
unsigned char c[2];
};
@SergNikitin
SergNikitin / virtFuncOverload.cpp
Last active December 24, 2015 20:08
Virtual functions overload test
#include <iostream>
class A {
public:
virtual int foo(int *num) {
const int height = 150; //in cm
int sum = height + *num;
std::cout << sum << std::endl;
return sum;
};
class ListNode {
friend class List;
public:
ListNode* nextNodePointer;
ListNode* previousNodePointer;
int value;
private:
/**
* Constructs an empty element of the list, points to NULL by default
template <typename T>
VectorIterator<T>& VectorIterator<T>::operator=(VectorIterator<T>& iter) {
elemPointer = iter.elemPointer;
return *this;
}
@SergNikitin
SergNikitin / example.h
Last active August 29, 2015 13:56
template class inheritance question
// class derived_class;
class main_class {
public:
derived_class foo(); // error: ‘derived_class’ does not name a type
};
derived_class main_class::foo() {} // error: ‘derived_class’ does not name a type
template <typename T>
static inline void setTimerSettingsToDefaultByNum(uint_fast8_t timerNum) {
// enable timer interrupt
CpuTimer0Regs.TCR.bit.TIE = 1;
// free run mode switch on
CpuTimer0Regs.TCR.bit.FREE = 1;
CpuTimer0Regs.TCR.bit.SOFT = 0;
// set preload value and timer prescaler
CpuTimer0Regs.PRD.all = 0xFFFF;
CpuTimer1Regs.TPR.bit.TDDR = 0xFF;
static const u08 BTN_NOT_PRESSED = 1;
int main() {
static u08 previousBtnState[4] = {BTN_NOT_PRESSED,
BTN_NOT_PRESSED,
BTN_NOT_PRESSED,
BTN_NOT_PRESSED};
}
/*
@SergNikitin
SergNikitin / gist:d8d9441120d00459201d
Created July 30, 2014 18:21
building sdl_image as CMake external project
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
project(freetype_test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
set(LIBS_DIR ${PROJECT_SOURCE_DIR}/libs)
set(FREETYPE_VER "2.5.3")
set(SDL2_VER "2.0.3")
@SergNikitin
SergNikitin / gist:458e625f0808a9f8daee
Created July 30, 2014 18:32
sdl_image linking error
libtool: link: gcc -I/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project/include -I/usr/local/include/SDL2 -D_REENTRANT -o showimage showimage.o -Wl,-rpath -Wl,/usr/local/lib -pthread -L/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project-build ./.libs/libSDL2_image.a -L/usr/local/lib -lSDL2 -pthread
/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project-build/libSDL2.a(SDL_dynapi.c.o): In function `get_sdlapi_entry':
/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:227: undefined reference to `dlopen'
/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:228: undefined reference to `dlsym'
/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:227: undefined reference to `dlopen'
/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:228: undefined reference to `dlsym'
/home/snikitin/_src/img_glypher/libs/SDL2/src/sdl2_project/src/dynapi/SDL_dynapi.c:227: undefined referenc
@SergNikitin
SergNikitin / ptr_cast.cpp
Created September 6, 2016 08:53
std::unique_ptr cast helpers
/**
* @brief Converts std::unique_ptr of base type to std::unique_ptr of derived type
* by using static_cast internally
* @details Ownership of the object is transfered to the returned std::unique_ptr.
* It is somewhat analogous to std::static_ptr_cast
*/
template<typename Derived, typename Base, typename Deleter>
std::unique_ptr<Derived, Deleter> static_ptr_cast(std::unique_ptr<Base, Deleter> base)
{
auto deleter = base.get_deleter();