小编Eri*_*ren的帖子

是否有任何c/c ++编译器可以警告(或给出错误)或枚举转换为int?

清理使用硬编码整数文字而不是枚举的旧c/c ++代码,找到功能声明已被正确重构但不是正文的地方是很繁琐的.例如

enum important {
  little = 1,
  abit = 2,
  much = 3
};

void blah(int e)
{
  // magic stuff here
}

void boing(int e) { ... }

void guck(important e)
{
  switch (e) {
    case 3:  // this would be a good place for a warning
      blah(e);  // and this
      break;
    default:
      boing((int)e); // but this is OK (although imperfect and a warning would be acceptable)
      break;
  }
}
Run Code Online (Sandbox Code Playgroud)

注释/修改每个枚举类型或通过代码搜索它们也是相当多的工作,因为存在非常多的不同枚举,因此这不是优选的,但可以是可接受的解决方案.

我不需要它在我们的任何主编译器或其他工具(主要是gcc)或平台(大多数),手动运行几次就足够了,但我更喜欢不太深奥或昂贵的东西.

c c++ enums warnings

6
推荐指数
1
解决办法
866
查看次数

gdb通过步行帧指针回溯

有时会出现一些小的堆栈损坏,导致gdb无法执行"回溯",我创建了下面的gdb宏(x86-64,可以很容易地为x86工作),这取决于关闭省略帧指针( ie -fno-omit-frame-pointer)并显示回溯中的函数.但是,我希望它也显示参数值,理想情况下可以选择其中一个帧.(例如"frame 0x0123456789ABCDEF").

define et
set $frameptr = $rbp
while $frameptr != 0
 set $oldbp = *((void**)($frameptr+8))

 print $frameptr
 print $oldbp
 info symbol $oldbp

 set $frameptr = *((void**)($frameptr))
 end
end
Run Code Online (Sandbox Code Playgroud)

linux gdb

5
推荐指数
0
解决办法
1017
查看次数

使用库时的openssl调试信息

使用库API和使用“ s_client -debug”时,是否可以接收相同的调试输出?(我正在尝试调试握手问题,并且在每个系统上都安装命令行工具并不可行)

openssl

2
推荐指数
1
解决办法
4577
查看次数

标签 统计

c ×1

c++ ×1

enums ×1

gdb ×1

linux ×1

openssl ×1

warnings ×1