- 浏览: 208098 次
- 性别:
- 来自: 北京
最新评论
-
fuliang:
more cleanner than before
Big Integer Arithmetic -
yaojingguo:
Hi, Liang LiangThanks for the i ...
Redirect and restore stdout in C -
fuliang:
使用gcc编译.cpp,可以使用-lstdc++选项,这样gc ...
Redirect and restore stdout in C
文章列表
The code:
#include <stdio.h>
#define COLOR_TABLE \
X(red, "red") \
X(green, "green") \
X(blue, "blue")
#define X(a, b) a,
enum COLOR {
COLOR_TABLE
};
#undef X
#define X(a, b) b,
char *color_name[] = {
COLOR_TABLE
};
#undef X
i ...
Diff between differerent revisions. Example:
svn diff -r 13401:13747 bi/data-integrator/src/clojure/di/di.clj
Colordiff: http://www.zalas.eu/viewing-svn-diff-result-in-colors
I develop the code with x86 gcc.
The C code:
#include <stdio.h>
void test() {
int i;
int array[3] = {0};
for (i = 0; i < 3; i++)
printf("array[%d] = %d\n", i, array[i]);
}
int main(int argc, const char *argv[]) {
test();
return 0;
}
Th ...
C array initialization
- 博客分类:
- C/C++
For fewer initializers, refer to 4.9 Initialization in K&R and 6.7.8 Initialization in C99 standard.
#include <stdio.h>
// in bss section. static storage. initialized to 0
int global_array[10];
void global() {
int i;
printf("=== global ===\n");
for (i = 0; ...
Example of snprintf
- 博客分类:
- C/C++
#include <stdio.h>
int main(int argc, const char *argv[]) {
int count;
int i;
char buf[10];
for (i = 0; i < 10; i++)
buf[i] = 1;
count = snprintf(buf, 10, "%s", "abc");
printf("count: %d, string: %s\n", count, buf);
for (i = 0; i & ...
#include <stdio.h>
struct rx_desc {
int len;
int status;
};
struct rx_desc rx_ring[2];
int main(int argc, const char *argv[]) {
struct rx_desc* rx;
// Intialization
rx_ring[0].len = 1;
rx_ring[0].status = 10;
rx_ring[1].len = 2;
rx_ring[1].status = 20;
rx = & ...
Struct array member
- 博客分类:
- C/C++
C code:
#include <stdio.h>
// This struct does not store jp_data:
// +-+-+-+-+
// 0+-+-+-+-+ jp_len
// 3 2 1 0
struct zero_size_array_struct {
int jp_len;
char jp_data[0];
};
// This struct stores a char pointer:
// +-+-+-+-+
// 1+-+-+-+-+ jp_data
/ ...
Code:
#include <stdio.h>
struct Nsreq_accept {
int req_s;
};
struct Nsreq_shutdown {
int req_s;
int req_how;
};
union Nsipc {
struct Nsreq_accept accept;
struct Nsreq_shutdown shutdown;
};
union Nsipc* nsipcbuf;
struct Nsreq_accept* p;
struct Nsreq_accept accept ...
#if and #ifdef in C
- 博客分类:
- C/C++
#include <stdio.h>
#define debug 0
int main(int argc, const char *argv[]) {
#if debug
printf("#if\n");
#endif
#ifdef debug
printf("#ifdef\n");
#endif
}
#include <stdio.h>
struct person {
int sex;
int no;
};
int main(int argc, const char *argv[]) {
int array_1[3] = {1, 2, 3};
int array_2[3] = {1, 2, 3,};
struct person xiao_yu = {
1, 100
};
struct person xiao_yue = {
1, 100,
};
return 0;
}
Refer to 6.7 ...
#include <stdio.h>
struct packet_buf {
char buf[16];
} __attribute__((aligned(16)));
struct packet_buf buf_ring[4];
int main(int argc, const char *argv[]) {
int i;
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
// &buf_ring[i] and buf_ring[i].buf have the same v ...
#include <stdio.h>
int main(int argc, const char *argv[]) {
int base = 0xf0000000;
// difference between base and 0x100000000
int diff = -base;
printf("%08x, %08x\n", base, diff);
return 0;
}
Code:
#include <stdio.h>
int info(int no) {
printf("no: %d\n", no);
}
int main(int argc, const char *argv[]) {
int (*fp)(int);
fp = info;
printf("function pointer: %p\n", fp);
fp = &info;
printf("function pointer: %p\n", fp);
...
Compute 16-bit One's Complement Sum
Date: 03/20/2002 at 13:54:13
From: John
Subject: How to compute 16-bit one's complement sum
I would like to know how to compute one's complement sum. In my TCP/IP
book it says, "to compute the IP checksum for outgoing datagram, the
value of checks ...
#include <stdio.h>
int array[10] = {
[7] = 700,
};
int main(int argc, const char *argv[]) {
printf("%d\n", array[7]);
return 0;
}