Skip to content

Instantly share code, notes, and snippets.

View djg's full-sized avatar
💭
I may be slow to respond.

Dan Glastonbury djg

💭
I may be slow to respond.
View GitHub Profile
// Overloading operator, to allow custom list of objects to be passed
// eg: object obj()[, , , ];
struct list
{
...
list& operator,(list l);
...
};
void sort(int* A, int n)
{
for (int i = 0; i < n; ++i)
for (int j = i+1; j < n; ++j)
if (A[j] < A[i])
{
int tmp = A[i];
A[i] = A[j];
A[j] = tmp;
}
void sort2(int* A, int n)
{
for (int i = 0; i < n; ++i)
{
int min = i;
for (int j = i+1; j < n; ++j)
{
if (A[j] < A[min])
min = j;
}
// Compile with cl /O2 sorting.cpp winmm.lib
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
void exch(int& a, int& b)
{
int tmp = a; a = b; b = tmp;
}
enum Flags
{
Flag1 = 0x1,
Flag2 = 0x2,
Flag3 = 0x4,
Flag4 = 0x8
};
Flags operator|(Flags a, Flags b)
{
// One of many test.cpp I found. I think this one was for examining the generated assembly.
#include "xmmintrin.h"
#if 0
struct Vec3
{
float x, y, z;
__forceinline Vec3() {};
__forceinline Vec3(float X, float Y, float Z) : x(X), y(Y), z(Z) {};
__forceinline Vec3 operator*(const Vec3& t) const { return Vec3(x*t.x, y*t.y, z*t.z); };
// Yet another test. Also had a .obj along side.
#include <winsock2.h>
int
main()
{
u_short x = 1;
x = htons(x);
return x;
// Another test. RGB->YCoCg conversion. Think I discovered a problem with negative
// values being returned on RGB->YCoCg->RGB.
#include <stdio.h>
struct IVect { int x, y, z; };
/*
* [Y ] = [ 1/4 1/2 1/4][R] R, G, B = [0..255] => Y = [0..255], Co, Cg = [-128..127]
* [Co] [ 1/2 0 -1/2][G]
* [Cg] [-1/4 1/2 -1/4][B]
template <class CODE>
class A
{
protected:
CODE code;
// This is wrong, it needs to me template <class EVENT, class CODE> friend EVENT& createEvent(...)
template <class EVENT>
friend EVENT& createEvent(CODE code, bool down, bool repeat);
};
@djg
djg / gist:1541938
Created December 30, 2011 23:05
Please Kill Me
>graphics.lib(material.obj) : error LNK2019: unresolved external symbol "public: __thiscall boost::archive::basic_binary_oprimitive<class boost::archive::binary_oarchive,class std::basic_ostream<char,struct std::char_traits<char> > >::~basic_binary_oprimitive<class boost::archive::binary_oarchive,class std::basic_ostream<char,struct std::char_traits<char> > >(void)" (??1?$basic_binary_oprimitive@Vbinary_oarchive@archive@boost@@V?$basic_ostream@DU?$char_traits@D@std@@@std@@@archive@boost@@QAE@XZ) referenced in function "public: virtual __thiscall boost::archive::binary_oarchive_impl<class boost::archive::binary_oarchive>::~binary_oarchive_impl<class boost::archive::binary_oarchive>(void)" (??1?$binary_oarchive_impl@Vbinary_oarchive@archive@boost@@@archive@boost@@UAE@XZ)
1>graphics.lib(globallighting.obj) : error LNK2001: unresolved external symbol "public: __thiscall boost::archive::basic_binary_oprimitive<class boost::archive::binary_oarchive,class std::basic_ostream<char,struct std::char_traits<char> > >::~b