所以我正在开发一个非常大的代码库,最近升级到gcc 4.3,它现在触发了这个警告:
警告:不推荐将字符串常量转换为'char*'
显然,解决这个问题的正确方法是找到每个声明
char *s = "constant string";
Run Code Online (Sandbox Code Playgroud)
或函数调用如:
void foo(char *s);
foo("constant string");
Run Code Online (Sandbox Code Playgroud)
并使他们成为const char指针.但是,这意味着触及564个文件,最小,这不是我希望在此时执行的任务.现在的问题是我正在运行-werror,所以我需要一些方法来扼杀这些警告.我怎样才能做到这一点?
我正在尝试编写"The C Programming Language"(K&R)一书中的这段代码.它是UNIX程序的一个简单版本wc:
#include <stdio.h>
#define IN 1; /* inside a word */
#define OUT 0; /* outside a word */
/* count lines, words and characters in input */
main()
{
int c, nl, nw, nc, state;
state = OUT;
nl = nw = nc = 0;
while ((c = getchar()) != EOF) {
++nc;
if (c == '\n')
++nl;
if (c == ' ' || c == '\n' || c == '\t')
state = OUT; …Run Code Online (Sandbox Code Playgroud) 新的Show(),ShowDialog()和Application.Run()函数有什么区别?在main(winforms)我看到:
Application.Run(new Form1());
Run Code Online (Sandbox Code Playgroud)
然后,对于Form1,我还看到Form1.Show()了描述:"向用户显示控件." 对于ShowDialog,它说"将表单显示为模式对话框".
这是什么意思?
它们的用途是什么,哪种最常见?
嘿,我想知道为什么返回类型的事件如
private void button1_Click(object sender, EventArgs e)
Run Code Online (Sandbox Code Playgroud)
永远无效?
它还可以返回任何其他值吗?
我有一组人物对象(IEnumerable),每个人都有一个年龄属性.
我想在这个年龄属性上生成集合的统计数据,例如Max,Min,Average,Median等.
使用LINQ最优雅的方法是什么?
嗨,我是python的新手,想要在数组中输入.关于数组没有很好地描述python doc.另外我觉得我对python中的for循环有一些打嗝.
我在python中提供了我想要的C代码片段:
C代码:
int i;
printf("Enter how many elements you want: ");
scanf("%d", &n);
printf("Enter the numbers in the array: ");
for (i = 0; i < n; i++)
scanf("%d", &arr[i]);
Run Code Online (Sandbox Code Playgroud) 我有一个清单:
List<double> final=new List<double>();
final.Add(1);
final.Add(2);
final.Add(3);
Run Code Online (Sandbox Code Playgroud)
我可以使用哪种方法来查找此列表的模式?此外,如果有两种模式,该函数将返回两者中较小的一种.
看起来GCC有一些优化认为来自不同翻译单元的两个指针永远不会相同,即使它们实际上是相同的.
码:
main.c中
#include <stdint.h>
#include <stdio.h>
int a __attribute__((section("test")));
extern int b;
void check(int cond) { puts(cond ? "TRUE" : "FALSE"); }
int main() {
int * p = &a + 1;
check(
(p == &b)
==
((uintptr_t)p == (uintptr_t)&b)
);
check(p == &b);
check((uintptr_t)p == (uintptr_t)&b);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
公元前
int b __attribute__((section("test")));
Run Code Online (Sandbox Code Playgroud)
如果我用-O0编译它,它会打印出来
TRUE
TRUE
TRUE
Run Code Online (Sandbox Code Playgroud)
但是用-O1
FALSE
FALSE
TRUE
Run Code Online (Sandbox Code Playgroud)
所以p并且&b实际上是相同的值,但是编译器优化了它们的比较,假设它们永远不会相等.
我无法弄清楚,哪种优化做到了这一点.
它看起来不像严格的别名,因为指针是一种类型,而-fstrict-aliasing选项不会产生这种效果.
这是记录在案的行为吗?或者这是一个错误?
我打开了一个文件,在指针的地址找到了流ptr.我试图查看文件是否为空.使用以下内容
if (fgetc(ptr) != EOF)
Run Code Online (Sandbox Code Playgroud)
按预期工作.当文件为空时,不执行该语句.当文件不为空时,不执行该语句.
但是,使用
if (!feof(ptr))
Run Code Online (Sandbox Code Playgroud)
总是执行声明.
为什么会这样?有没有办法使用这个feof功能?