Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么emacs显示这些警告和错误?_C_Emacs_Flycheck - Fatal编程技术网

为什么emacs显示这些警告和错误?

为什么emacs显示这些警告和错误?,c,emacs,flycheck,C,Emacs,Flycheck,我正试图从VIM切换到Emacs,但在让语法检查器为一个小型C项目工作时遇到了问题。我尝试了Flymake和Flycheck作为语法检查器,它们都显示了一个不存在的编译器错误。我目前有3个文件,poker.ccards.c和cards.h 这是扑克 #include "cards.h" #include <stdio.h> #include <stdlib.h> int main() { struct Deck *deck = malloc(sizeof(stru

我正试图从VIM切换到Emacs,但在让语法检查器为一个小型C项目工作时遇到了问题。我尝试了Flymake和Flycheck作为语法检查器,它们都显示了一个不存在的编译器错误。我目前有3个文件,
poker.c
cards.c
cards.h

这是扑克

#include "cards.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{

  struct Deck *deck = malloc(sizeof(struct Deck)); 
  struct Hand *hand = malloc(sizeof(struct Hand));
   clear_deck(deck);
  deck = init_deck(deck);
  deck = shuffle(deck);
  int c = deal(deck, hand);
  if(c != 5) {
    printf("error: not enough cards delt");
  } else {
    print_hand(hand);
  }
  return 0;
}
两个语法检查器都显示该行的错误

  struct Hand *hand = malloc(sizeof(struct Hand));
以及所有其他功能的警告。这是
*Flycheck错误*
缓冲区

    9  37 error           invalid application of ‘sizeof’ to incomplete type ‘struct Hand’... (c/c++-gcc)
   10   4 warning         implicit declaration of function ‘clear_deck’... (c/c++-gcc)
   11   3 warning         implicit declaration of function ‘init_deck’... (c/c++-gcc)
   11   8 warning         assignment makes pointer from integer without a cast... (c/c++-gcc)
   12   3 warning         implicit declaration of function ‘shuffle’... (c/c++-gcc)
   12   8 warning         assignment makes pointer from integer without a cast... (c/c++-gcc)
   13   3 warning         implicit declaration of function ‘deal’... (c/c++-gcc)
   17   5 warning         implicit declaration of function ‘print_hand’... (c/c++-gcc)

我觉得emacs在进行语法检查之前没有运行C预处理器。有什么方法可以让语法检查器正常工作吗?

除此之外,头文件:cards.h需要一个“include guard”文件

#ifndef CARDS_H
#define CARDS_H

typedef enum {
  TWO,
  THREE,
  FOUR,
  FIVE,
  SIX,
  SEVEN,
  EIGHT,
  NINE,
  TEN,
  JACK,
  QUEEN,
  KING,
  ACE,
} Rank;


typedef enum {
  SPADES,
  CLUBS,
  HEARTS,
  DIAMONDS,
} Suit;

struct Card {
  Rank rank;
  Suit suit;
  int shuffled;
};

struct Deck {
  struct Card cards[52];
  int shuffled;
};

struct Hand{
  struct Card cards[5];
};

void * shuffle(struct Deck *deck);
void * init_deck(struct Deck *d);
void clear_deck(struct Deck *d);
void print_deck(struct Deck *d);
void print_hand(struct Hand *h);
int deal(struct Deck *deck, struct Hand *hand);

#endif // CARDS_H
我编译了文件:poker.c 带有用于错误检查的附加项

启用所有警告(linux ubuntu 14.04和gcc-Wall-Wextra-pedantic…)

它编译得很干净

#include "cards.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{
    struct Deck *deck = malloc(sizeof(struct Deck)); 
    if( NULL == deck )
    { // then malloc failed
        perror( "malloc for deck failed" );
        exit( EXIT_FAILURE );
    }

    // implied else, malloc successful

    struct Hand *hand = malloc(sizeof(struct Hand));
    if( NULL == hand )
    { // then, malloc failed
        perror("malloc for hand failed" );
        exit( EXIT_FAILURE );
    }

    // implied else, malloc successful

    clear_deck(deck);
    deck = init_deck(deck);
    deck = shuffle(deck);
    int c = deal(deck, hand);

    if(c != 5) 
    {
        printf("error: not enough cards delt\n"); // \n so will immediate be output

    } 

    else 
    {
        print_hand(hand);
    }

    return 0;
} // end function: main
这是我编译的代码

#include "cards.h"
#include <stdio.h>
#include <stdlib.h>

int main()
{
    struct Deck *deck = malloc(sizeof(struct Deck)); 
    if( NULL == deck )
    { // then malloc failed
        perror( "malloc for deck failed" );
        exit( EXIT_FAILURE );
    }

    // implied else, malloc successful

    struct Hand *hand = malloc(sizeof(struct Hand));
    if( NULL == hand )
    { // then, malloc failed
        perror("malloc for hand failed" );
        exit( EXIT_FAILURE );
    }

    // implied else, malloc successful

    clear_deck(deck);
    deck = init_deck(deck);
    deck = shuffle(deck);
    int c = deal(deck, hand);

    if(c != 5) 
    {
        printf("error: not enough cards delt\n"); // \n so will immediate be output

    } 

    else 
    {
        print_hand(hand);
    }

    return 0;
} // end function: main
#包括“cards.h”
#包括
#包括
int main()
{
结构甲板*Deck=malloc(sizeof(结构甲板));
if(NULL==组)
{//然后malloc失败了
perror(“malloc for deck失败”);
退出(退出失败);
}
//否则,malloc成功了
struct Hand*Hand=malloc(sizeof(struct Hand));
如果(空==手)
{//然后,malloc失败了
perror(“malloc for hand失败”);
退出(退出失败);
}
//否则,malloc成功了
清理甲板(甲板);
甲板=初始甲板(甲板);
牌组=洗牌(牌组);
int c=交易(甲板、手);
如果(c!=5)
{
printf(“错误:没有足够的数据卡”);//\n因此将立即输出
} 
其他的
{
手工印刷;
}
返回0;
}//结束函数:main

这并没有解决问题,我已经知道程序是有效的,因为它按照预期编译和运行。我的问题比C代码更针对flycheck和emacs。你有没有告诉emacs包含cards.h文件(如在何处找到它)?你有没有将此添加到init.el文件:“(在init hook#“global-flycheck-mode”之后添加hook)?在检查poker.c时,cards.h文件是否在emac缓冲区中?您告诉flycheck将哪个“语法检查器”用于.c和.h文件?对于语法检查器:c/c++-gcc,有几个选项:flycheck gcc args,您可以使用它们告诉gcc-I