Skip to content

Instantly share code, notes, and snippets.

@DamonHao
DamonHao / linux_liee_eidan.cpp
Created October 11, 2014 07:11
C++ linux little edian
void test()
{
int a = 0x00002;
char p = ((char*)(&a))[0];
cout << (int)p << endl;
}
int main()
{
@DamonHao
DamonHao / class_static_variable.cc
Last active July 1, 2017 13:44
C++ 类的static成员变量和函数内static变量初始化时机
/*
C++ static 变量初始化时间就和普通static的初始化时间是一样的。
*/
#include <iostream>
using namespace std;
class A
{
public:
@DamonHao
DamonHao / const_optimize.cpp
Created September 17, 2014 01:56
C++ const 优化
/*
* test_cpp.cc
*
* Created on: May 29, 2014
* Author: damonhao
*/
#include <iostream>
#include <string>
using namespace std;
@DamonHao
DamonHao / java_equal.java
Created September 12, 2014 02:42
java equal
public class A {
public int n=1;
public static void main(String[] args) {
A obj1=new A();
A obj2=new A();
A obj3=obj1;
String s1=new String("abc");
String s2=new String("abc");
String s3="abc";
System.out.println(obj1==obj2);
@DamonHao
DamonHao / bind_copy_parameter.cc
Last active August 29, 2015 14:05
boost bind copy parameter
/*
* test_bind.cc
*
* Created on: Aug 10, 2014
* Author: damonhao
*/
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <boost/function.hpp>
@DamonHao
DamonHao / hex_string_to_ulong.cc
Created August 6, 2014 09:29
converting Hex string to unsigned long
#include <sstream>
#include <iostream>
int main()
{
std::string s("0xFFF000");
unsigned long value;
std::istringstream iss(s);
iss >> std::hex >> value;
@DamonHao
DamonHao / func_reutrn_value.cc
Created July 21, 2014 15:02
different case of function reutrn value
#include <iostream>
using namespace std;
struct A
{
int a;
int b;
int c;
};
@DamonHao
DamonHao / printf_uint_64_t.c
Created July 14, 2014 02:42
c printf uint_64
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <stdio.h>
int main()
{
uint64_t ui64 = 90;
printf("test uint64_t : %" PRIu64 "\n", ui64);
return 0;
}
@DamonHao
DamonHao / main.cc
Last active August 29, 2015 14:02
Don't write namespace usings in a header file or before an #include.
#include "s1.h"
#include "s2.h"
#include "s3.h"
/*
If s3.h comes before s2.h, B::g will call A::f(int).
Else if sl.h comes before s2.h, B::g will call A::f(double).
Else B::g won't compile at all.
*/
@DamonHao
DamonHao / test_io.cc
Last active August 29, 2015 14:02
libev cpp example
/*
* test_io.cc
*
* Created on: Jun 4, 2014
* Author: damonhao
*/
#include <ev++.h>
#include <stdio.h>