Why put void in params?

前端 未结 6 1037
别跟我提以往
别跟我提以往 2020-12-08 19:33

What\'s the reason for putting void inside of the params?

Why not just leave it blank?

void createLevel(void);

void createLevel();
6条回答
  •  轮回少年
    2020-12-08 20:19

    In C++ there is no difference.

    The following applies only to C:

    Actually, according to this thread:

    when you declare somewhere a function func(), this means you don't say anything about it's aguments. On the otherhand func(void) means NO ARGUMENTS

    perfect_circle even posted a wonderful code example to illustrate the point:

    skalkoto@darkstar:~$ cat code.c
    #include 
    
    int main()
    {
            void func(void);
            func(3);
    return 0;
    }
    
    void func(int a)
    {
            printf("Nothing\n");
    }
    skalkoto@darkstar:~$ gcc code.c
    code.c: In function `main':
    code.c:6: error: too many arguments to function `func'
    skalkoto@darkstar:~$ cat code1.c
    #include 
    
    int main()
    {
            void func();
            func(3);
            return 0;
    }
    
    void func(int a)
    {
            printf("Nothing\n");
    }
    skalkoto@darkstar:~$ gcc code1.c
    skalkoto@darkstar:~$ ./a.out
    Nothing
    skalkoto@darkstar:~$
    

提交回复
热议问题