show follow-fork-mode Debugger response to a program call of fork or vfork is "parent".set follow-fork-mode mode parent The original process is debugged after a fork. The child process runs unimpeded. This is the default. child The new process is debugged after a fork. The parent process runs unimpeded.show detach-on-fork Whether gdb will detach the child of a fork is on.set detach-on-fork mode on The child process (or parent process, depending on the value of follow-fork-mode) will be detached and allowed to run independently.
Read More →
#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <set>#include <sys/wait.h> using namespace std; int main(int argc, char const *argv[]) { int num = 5; set<int> pid_set; int seq = 0; pid_t temp_pid; for (int i=0; i < num; i++) { temp_pid = fork(); if (temp_pid ==0 || temp_pid == -1) break; pid_set.insert(temp_pid); seq++; } if (temp_pid == 0) { for (int j=0; j < 10; j++) { printf("%d---%d---%d\n", getpid(), j, seq); if (seq == 0) { char *p = NULL; printf("%c", *p); } sleep(seq); } return 0; } else { int stat = 0; int ret = 0; while(true){ ret = waitpid(0, &stat, WNOHANG); if (ret > 0) { set<int>::iterator position = pid_set.
Read More →
double小数前后加起来的有效数字只有16位,当给定的double有效数在16位以内转换为字符串不会丢失精度
Code:
char precisionStr[100] = {0}; double precisionTest = 11.437565871234012; sprintf(precisionStr, "%.20f", precisionTest); cout << "precision----" << precisionStr << endl; precisionTest = 119.437565871234012; sprintf(precisionStr, "%.20f", precisionTest); cout << "precision----" << precisionStr << endl; Output:
precision----11.43756587123401224915 precision----119.43756587123401402550
项目级别,修改项目属性
整体IDE,修改etc/netbeans.conf,-J-Dfile.encoding=UTF-8
netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dfile.
Read More →
类型和安全检查不同
宏定义是字符替换,没有数据类型的区别,同时这种替换没有类型安全检查,可能产生边际效应等错误;
const常量是常量的声明,有类型区别,需要在编译阶段进行类型检查
编译器处理不同
宏定义是一个”编译时”概念,在预处理阶段展开,不能对宏定义进行调试,生命周期结束与编译时期;
const常量是一个”运行时”概念,在程序运行使用,类似于一个只读行数据
存储方式不同
宏定义是直接替换,不会分配内存,存储与程序的代码段中;
const常量需要进行内存分配,存储与程序的数据段中
不建议使用字符串常量到 char*的转换 char* p = "test"; 声明了一个指针,而这个指针指向的是全局的const内存区,如果你一定要写这块内存的话,那就是一个非常严重的内存错误 在声明字符串字面量时,应该加上const. const char *p = "test";
使用class object的指针略有不同,这是因为class object链接到一组我们可以调用(invoke)的操作行为(operations),举例来说检查fibnacci vector的第二个元素是否为1,我们可能会这么写:
if (!fibonacci.empty() && (fibonacci[1] == 1)) 上例中的fibonacci和empty()两字之间的逗号,称为dot成员选择运算符(member selection operator),用来选择想要施行的操作,如果要通过指针来指针来选择操作行为,必须改用arrow成员选择运算符:
由于指针可能未指向任何对象,所以先校验pv是否为非零值
if (pv && pv->empty() && ((*pv)[1] == 1))