简体   繁体   English

此函数声明中是否存在语法错误?

[英]Is there a syntax error in this function declaration?

This is from a textbook: 这来自一本教科书:

/* This function locates the address of where a new structure
   should be inserted within an existing list.
   It receives the address of a name and returns the address of a
   structure of type NameRec
*/
struct NameRec *linear Locate(char *name)
{
...
}

I understand it returns a pointer to a struct NameRec. 我了解它会返回指向结构NameRec的指针。 Why is "linear" there and why is there a space between "linear" and "Locate"? 为什么“线性”在那里?为什么“线性”和“位置”之间有空间?

#define linear

will make it syntactically correct even if it wasn't before (though, technically, you'd probably want a #undef linear beforehand to avoid possible conflicting macro definitions). 即使不是以前,也可以使它在语法上正确(不过,从技术上讲,您可能需要事先使用#undef linear以避免可能发生的宏定义冲突)。

It depends entirely on the context of the code, which you haven't shown. 它完全取决于未显示的代码的上下文 As it stands now, with no header inclusions or definitions like -Dlinear= on the compiler command line, it would not compile in a standards-conformant environment without extensions. 到目前为止,在编译器命令行上没有头文件包含或-Dlinear=类的定义,如果没有扩展,它将无法在符合标准的环境中进行编译。

The best way to tell, of course, is to just try to actually compile the thing and see what happens :-) 当然,最好的告诉方法是尝试实际编译该东西,然后看看会发生什么:-)

Given that the solutions link for chapter 13 (the one you're asking about) has no mention of the linear word in the solution, I'd say it's a safe bet to assume your book is incorrect. 鉴于第13章的解决方案链接 (您要问的那个) 没有提及解决方案中的linear词,我想肯定地说您的书是不正确的。 I'd consider contacting the author (apparently currently working at FDU in New Jersey) to clear it up. 我会考虑与作者联系(显然目前正在新泽西州的FDU工作)以解决问题。

It's a typo in the book. 这是本书中的错字。 See the locate function here: 在这里查看定位功能:

https://users.ipfw.edu/chansavj/ACY2017/ANSI_C/ANSI_C_4thEd/Solutions%20to%20Exercises%20(Windows)/Solutions/83556-0s/Ch13/pgm13-5ex3.c https://users.ipfw.edu/chansavj/ACY2017/ANSI_C/ANSI_C_4thEd/Solutions%20to%20Exercises%20(Windows)/Solutions/83556-0s/Ch13/pgm13-5ex3.c

(Posted by ta.speot.is in the comments) (由ta.speot.is发表在评论中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM