我已经在我的苹果电脑上安装了使用的GCC 4.8。除了像scanf和printf这样的某些函数,程序编译得很好,没有任何错误/警告,即使我没有包括它们各自的库,比如cstdio,其他一切都很好。有什么办法可以让GCC (更具体地说是G++,因为我正在处理C++程序)在输入这样的代码时抛出一个错误?下面的代码在我的机器上编译得很好:
#include <iostream>
//Notice I did not include cstdio but my program uses printf later on
int main()
{
printf("Hello W
有谁能向我解释一下为什么会这样做呢?
int main()
{
int a = mymethod(0);
}
int mymethod(int b)
{
return b;
}
但这并不意味着:
int main()
{
mymethod(0);
}
void mymethod(int b)
{
return;
}
我认为在C/C++中需要前向声明,但这里是一个反例。隐式声明在C中是如何工作的?
考虑这个C程序:
int main()
{
puts("Hello world!");
return 0;
}
这段代码编译和运行良好,据我所知,这是合法的C89。然而,我对此并不是百分之百确定。用clang在C99模式下编译会告诉我implicit declaration of function 'puts' is invalid in C99 (这让我认为C标准一定在C99中改变了,才使得隐式函数声明是非法的,这正是我试图确认的)。
隐式函数声明在C89中合法吗?(即使这不是一个好主意(除非你是在一个混淆的C代码挑战中))
我有一个小的实时操作系统,它不使用glibc,并且我已经用字符串编写了自己的函数(例如tolower)。
当编译时,我得到了这个错误:
common/string.c:11:6: error: conflicting types for built-in function ‘tolower’ [-Werror]
有没有一个CFLAGS来解决这个问题?
更新答案: use -fno-builtin
我是一个新的C开发人员(我习惯于用Java编程),并且尝试过create,我认为这是一个简单的bool函数。虽然我收到了一个错误,但我不知道如何修复:
#include <stdio.h>
#include <stdlib.h>
typedef enum { false, true } bool;
int main() {
int currentNumber, round = 1;
printf("Numbers generated will be between 1 and 20. \n");
currentNumber = r
我正在创建一个简单的程序,其中我正在使用long long int,但我得到了编译器错误。请帮助我解决这个错误。
错误] countTrees的冲突类型
我在这条线上出错了
long long int countTrees(long long int numKeys)
这是我的代码:
#include <stdio.h>
#include <math.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
long long int n;
会议记录:
> type lookma.c
int main() {
printf("%s", "no stdio.h");
}
> cl lookma.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
lookma.c
Microsoft (R) Incremental Linker Version 8.00.
对于代码中的第一次出现,我会得到“函数的隐式声明”,但其他事件没有突出显示,我想同时查看所有这些事件。如下所示。
我正在使用:用于ARM嵌入式处理器的GNU工具(arm-none-eabi-gcc)版本: 2.4-201503242026。
writeReg(ADDR_IP_TR0,saved_TR0); <------ There is implicit declaration of function
writeReg(ADDR_IP_TR2,saved_TR2); <------ Nothing
writeReg(ADDR_IP_TR3,saved_TR
当我试图编译时,我得到了以下错误:“compute”的冲突类型。
我的主要功能测试compute_GPA和compute_GPA sholuld计算平均分数!
我声明错了什么?,这是我的代码:
#include <stdio.h>
#include <ctype.h> /* for access to the toupper function */
/* Test a function that calculates the average of grades in a char array. main tests the function */
int mai
情况是,我有以下类,例如:
public class SendFile
{
public SendFile(Uri uri) { /* some code here */ }
public SendFile(string id) { /* some code here */ }
}
然后,我们知道如果我想解析构造函数,我不能这样做:
// some string defined which are called "address" and "id"
var sendFile = new SendFile(String.IsNullOrEmpt
斯蒂芬·普拉塔( Stephen )在他的书“C++ Primer Plus p 31”中说:
许多现有程序使用经典的C函数头:经典C下的main() // original C style,省略返回类型与声明函数为int类型相同。然而,C++已经逐步取消了这种使用。
然而,C++11草案3.6.1->2说
实现不应预定义主要功能。此功能不应超载。它应该有一个int类型的返回类型,但否则它的类型是实现定义的。
测试结果
$ g++ -Werror=pedantic MainCheck.cpp -o MainCheck
MainCheck.cpp:3:6: error: I
我收到了关于lstat被隐式声明的警告,但是应该在包含的头中显式声明它。
汇编如下:
// Standard library
#include <stdio.h>
// Feature test macro
#define _POSIX_C_SOURCE 200809L
// POSIX inclusions
#include <sys/stat.h>
// Function
int main()
{
struct stat x;
char* s = "/data/file";
char* t = "/data/link&
我不明白为什么线return (const C&)cc;不工作。
下面是代码和错误的粘贴。
#include <stdio.h>
class C
{
public:
int i;
explicit C(const C&) // an explicit copy constructor
{
printf("\nin the copy constructor");
}
explicit C(int i ) // an explicit constructor
{