【问题标题】:expected ')' before '*' token, can't seem to find error'*' 标记之前的预期 ')',似乎找不到错误
【发布时间】:2016-04-06 00:57:05
【问题描述】:

所以每当我尝试在我的服务器上运行我的 Makefile 时,它​​总是在 '*' 令牌之前给我错误是“Memory.c: 9 error: expected ')'。但是当我尝试自己运行它时电脑,它工作得很好。我一直试图找出问题所在,但似乎找不到。

我附上了我的程序这一部分中使用的 3 个文件。 Memory.c、Memory.h 和 ProcessInput.h。

这是Memory.c

/* Initializes memory */

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

#include "memory.h"


void initializeMemory(memory** memArray, int memSize)
{
    // Allocating space for memory array
    *memArray = malloc(memSize * sizeof(memory));
    if(*memArray == NULL)
    {
        fprintf(stderr, "Error allocating space for array of memory" );
        exit(1); // exit(1) = Unsuccessful exit
    }

    // Initializing the contents within memory array
    int i = 0;
    for(i = 0; i < memSize; i ++)
    {
        ((*memArray)[i]).occupied = false;
    }
}

这是Memory.h

// Definitions for Memory.c 

#define bool int
#define true 1
#define false 0

#include "ProcessInput.h"

// Include guards to prevent redefinition of struct
#ifndef MEMORY_H
#define MEMORY_H

typedef struct memoryDetail
{
    process process; 
    bool occupied;
} memory;

#endif

// Function declaration for memory.c
void initializeMemory(memory** memArray, int memSize);

ProcessInput.h 中唯一使用的是 ProcessInput.h 中定义的流程结构

这是 ProcessInput.h

// Include guards to prevent redefinition of struct
#ifndef PROCESSDETAIL_H
#define PROCESSDETAIL_H

typedef struct processDetail
{
    int timeCreated; 
    int processID; 
    int memorySize;
    int jobTime;
} process;

#endif

// function declarations for ProcessInput.c
void processInput(int* maxSize, int* count, process** processes, char* fileName);

我不太清楚为什么它给了我这个错误。我不知道我应该把丢失的右支架放在哪里。非常感谢任何建议!

编辑:据了解,这些是我查看但无济于事的以下问题。

error: expected ‘)’ before ‘*’ token

Multiple of same error while compiling "error: expected ')' before '*' token

http://www.dreamincode.net/forums/topic/288956-error-expected-before-token/

感谢大家的帮助!

【问题讨论】:

  • 补充一下,我已经尝试查看遇到相同问题的人在 Stack Overflow 上提出的其他问题,但为每个问题提供的解决方案已经由我完成。
  • 您应该编辑您的问题以包含您发现的问题的列表,以帮助防止它作为重复而被关闭。
  • 服务器是否运行 Linux 而您的计算机是否运行 Windows?
  • 是的,它正在运行 Linux。 John3136 的解决方案对我有用。当我去重命名我的文件时,我的一个小事后见之明。谢谢大家的帮助!

标签: c debugging


【解决方案1】:

#include "memory.h" 与 #include "Memory.h" 不同(即 C 区分大小写)

如果您尝试使用#include "myfile.h" 而不是#include "MyFile.h",则错误可能会更明显。在这种情况下,编译器恰好找到了系统memory.h。

【讨论】:

  • C 区分大小写吗?我认为这是特定于平台的东西,Unix 是,而 Windows 不是。
  • @immibis - 你是对的stackoverflow.com/questions/1951951/… 我仍然认为这是答案,因为我们正在使用一台计算机而不是另一台计算机 ;-)
  • C 语言本身的标识符绝对区分大小写。即您可以有两个单独的函数,分别称为 Main() 和 main()。但是文件名不是 C 标识符,在这种情况下 [原文如此] 它是由平台(和实现)定义的。
  • @immibis 大多数“Unix”文件系统(例如HFS)不区分大小写,这是正确的,但它们也保留大小写。虽然不允许在同一目录中同时存在名为“Foo.h”和“foo.h”的文件,但不能通过名称“foo.h”来引用“Foo.h”。
【解决方案2】:

&lt;memory.h&gt; 是来自准标准时代的 C 库的头文件。很有可能您的标准库仍然提供它,而编译器会使用那个而不是您的。

尝试重命名你的头文件,看看它是否有任何改变。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-22
    • 2015-01-19
    • 2017-02-19
    相关资源
    最近更新 更多