function-prototypes

How to find C functions without a prototype?

南笙酒味 提交于 2019-12-23 07:36:49
问题 Company policy dictates that every function in C source code has a prototype. I inherited a project with its own make system (so I cannot test it on gcc or Visual Studio) and found that one of the files has some static functions declared without prototypes. Is there a way (not necessarily with a compiler) to list all functions without prototypes in all .c files? 回答1: gcc has an option to warn you about this: gcc -Wmissing-prototypes You can turn this warning into an error to stop compilation

Issue with missing forward declaration in C++ [closed]

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 06:14:59
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . I have compiled following program without forward declaring function in C . It's successfully compiled and run in GCC without any warning or error. #include <stdio.h> int main() { int ret = func(10, 5); } int func(int i, int j) { return (i+j); } But, I have compiled following program without

Literal object and function constructor

旧巷老猫 提交于 2019-12-23 05:48:07
问题 I took this test on http://jsperf.com/literal-obj-vs-function-obj and Literal wins on FF6, Opera 10, IE8, but the Function method faster on Chrome 13.0.782.112, so which one is a better method to use? var A = { aa : function(){ var i, j=[]; var arr = ['Literal', 'Function']; for (i = 0; i < arr.length; i++){ j[i] = arr[i]; } return j[0]; } }; var A1 = A; var A2 = A1; A1.foo = ' Test'; alert(A1.aa() + A2.foo); //Function test function B(){ this.bb = function(){ var i, j=[]; var arr = ['Literal

Passing parameters to a prototyped function in javascript

こ雲淡風輕ζ 提交于 2019-12-22 07:37:48
问题 I've been recently experimenting with prototyping in javascript and I can't figure out why the following code doesn't work. What I would like to do is create a new instance of cheese with parameter n. function food(n) { this.n=n; } function cheese(n) { alert(this.n); } cheese.prototype=new food; new cheese('paramesian'); 回答1: You are creating a new Cheese instance, and the argument n is never used or assigned to the Cheese instance variable this.n , because that logic is only used on the Food

Problem extending class with javascript object prototype

自闭症网瘾萝莉.ら 提交于 2019-12-22 05:20:30
问题 I have got this problem... B is a base class, and A is a derived class... Event though A is derived from B, various objects of A points to the same object of B. I know i have assigned an object of B to the prototype of A to make A child of B. But different objects of A, they should have different address space to hold the variables, right? Can you anyone correct this? function B(){ this.obj = {}; } function A(){ } A.prototype = new B(); var a = new A(); var b = new A(); var c = new A();

Why use function prototypes?

自作多情 提交于 2019-12-21 03:37:08
问题 Why use function prototypes in C? It seems sort of redundant because we already declare the function name, argument types, and return type in the definition. Do the prototypes have to be declared before the function is defined or used for the optimizations? 回答1: Generally speaking, you don't need to explicitly declare functions because defining them also declares them. Here are two situations where you would need to: The definition of the function is in an external module. For example, if the

Declaration and prototype difference

試著忘記壹切 提交于 2019-12-20 20:16:56
问题 What is the difference between declaration and prototype in C? In which situations they are called declarations and in which prototypes? 回答1: TL;DR; All prototypes are declarations, but not all declarations are prototypes. Declaration is the generic terminology used in the standards, prototype is more specific. Quoting C11 , chapter §6.7 A declaration specifies the interpretation and attributes of a set of identifiers. [...] and from §6.7.6, Each declarator declares one identifier, and

extern on function prototypes?

限于喜欢 提交于 2019-12-19 15:06:48
问题 my_math.h // case 1 unsigned int add_two_numbers(unsigned char a, unsigned char b); //case 2 extern unsigned int add_two_numbers(unsigned char a, unsigned char b); What is the difference between case 1 and case 2? I never used extern for function prototypes but looking at someone's code (who is way more experienced than I am) I see extern always used when declaring the function prototype. Can anyone point please point the difference? (or point me to a link where I can find specific

extern on function prototypes?

吃可爱长大的小学妹 提交于 2019-12-19 15:06:14
问题 my_math.h // case 1 unsigned int add_two_numbers(unsigned char a, unsigned char b); //case 2 extern unsigned int add_two_numbers(unsigned char a, unsigned char b); What is the difference between case 1 and case 2? I never used extern for function prototypes but looking at someone's code (who is way more experienced than I am) I see extern always used when declaring the function prototype. Can anyone point please point the difference? (or point me to a link where I can find specific

Inline function prototype vs regular declaration vs prototype

心已入冬 提交于 2019-12-18 08:59:13
问题 What's the difference between inline function and then main like so: inline double cube(double side) { return side * side * side; } int main( ) { cube(5); } vs just declaring a function regularly like: double cube(double side) { return side * side * side; } int main( ) { cube(5); } vs function prototype? double cube(double); int main( ) { cube(5); } double cube(double side) { return side * side * side; } 回答1: An inline function can be defined in multiple translation units (cpp file + includes