gcc似乎没有使用以下代码生成警告.如何让它产生警告?
typedef enum
{
REG8_A,
REG8_B,
REG8_C
}REG8;
typedef enum
{
REG16_A,
REG16_B,
REG16_C
}REG16;
void function(REG8 reg8)
{
}
int main(void)
{
function(REG16_A); // Should warn about wrong enum
}
Run Code Online (Sandbox Code Playgroud) 我知道这听起来很奇怪.printf不应该改变任何东西,但没有它sendTo失败. 该程序是从c代码复制的,并由ubuntux86上的cpp编译器编译. 我有一个发送arp请求的程序.没有这个printf,sendTo失败了.奇怪的是,我做了一个最小的程序,根本不在printf变量中使用(仅在printf中),并且printf工作,没有printf它不起作用(在sendTo上获得无效的参数错误).
附件是一个最小版本,仅用于显示问题:
这个sendTo失败了:
int retVal = sendto(arp_fd, &pkt, sizeof(pkt), 0, (struct sockaddr *) &sa,sizeof(sa));
if (retVal < 0) {
perror("sendto");
close(arp_fd);
exit(1);
}
Run Code Online (Sandbox Code Playgroud)
添加它时,它工作:
struct ifreq ifr;//There is no use except in the printf
printf("MAC address: is %02x:%02x:%02x:%02x:%02x:%02x \n",
ifr.ifr_hwaddr.sa_data[0]&0xFF,
ifr.ifr_hwaddr.sa_data[1]&0xFF,
ifr.ifr_hwaddr.sa_data[2]&0xFF,
ifr.ifr_hwaddr.sa_data[3]&0xFF,
ifr.ifr_hwaddr.sa_data[5]&0xFF,
ifr.ifr_hwaddr.sa_data[4]&0xFF);
Run Code Online (Sandbox Code Playgroud)
完整的计划:
#include "sys/socket.h"
#include "sys/types.h"
#include "stdio.h"
#include "unistd.h"
#include "string.h"
#include "net/if.h"
#include "stdlib.h"
#include "arpa/inet.h"
#include "netinet/in.h"
#include "sys/ioctl.h"
#include "netpacket/packet.h"
#include "net/ethernet.h"
#define ETHER_TYPE_FOR_ARP 0x0806
#define HW_TYPE_FOR_ETHER 0x0001
#define OP_CODE_FOR_ARP_REQ …Run Code Online (Sandbox Code Playgroud) 可能重复:
我期望用C++编译器编译C代码有什么问题?
只是好奇我是否可以使用c ++编译器来编译c源代码?无论如何还有任何编译器完全支持c99标准吗?
通常我总是这样编译我的C代码:g ++ program.c -o program.exe
但我的大学教授要求我编译使用:g ++ -o -Wall -Wextra -Werror -pedantic -std = c ++ 0x program.exe program.c
(这对我来说是新的).
所以......我运行命令并得到以下错误:
eda.c: In function ‘int main()’:
eda.c:200: error: ISO C++ forbids variable-size array ‘v’
eda.c:207: error: ISO C++ forbids variable-size array ‘nfloat’
cc1plus: warnings being treated as errors
eda.c:215: warning: suggest a space before ‘;’ or explicit braces around empty body in ‘while’ statement
Run Code Online (Sandbox Code Playgroud)
这是我的程序的代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct {
float* data;
int size; …Run Code Online (Sandbox Code Playgroud) 当我尝试C在代码中构建一个项目时:使用GLM的ubuntu 14.04上的块我得到了这个
致命错误:cmath:没有这样的文件或目录
任何想法如何解决这一问题?