本文介绍了的函数内部函数的声明 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读,在C程序设计一书,并在第10章中的例子是这样的:

I am reading the book "Programming in C" and found in Chapter 10 an example like this:

#include <stdio.h>

void test (int  *int_pointer)
{
     *int_pointer = 100;
}

int main (void)
{
     void test (int  *int_pointer);
     int  i = 50, *p = &i;

     printf ("Before the call to test i = %i\n", i);

     test (p);
     printf ("After the call to test i = %i\n", i);

     return 0;
}

我理解的例子,但我不明白的行无效测试(INT * int_pointer); $ C>。为什么我再次定义测试的签名?那是地道的C 3

I understand the example, but I don't understand the line void test (int *int_pointer); inside of main. Why do I define the signature of test again? Is that idiomatic C?

推荐答案

这绝对不是地道的C,尽管是完全有效的(多个声明都还好,多重定义都没有)。这是不必要的,所以code仍然很好地工作,没有它。

It's definitely not idiomatic C, despite being fully valid (multiple declarations are okay, multiple definitions are not). It's unnecessary, so the code will still work perfectly without it.

如果可言,也许作者的意思做。

If at all, perhaps the author meant to do

void test (int *int_pointer);

int main (void) {

    ...

}

在情况下,函数定义是在放的main()

in case the function definition was put after main ().

这篇关于的函数内部函数的声明 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 18:59
查看更多