Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 789 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Untyped arguments in a C function declaration

#1
Recently I've been looking at the some of the C example code from the online resources of Steven Skiena's ["Algorithm Design Manual"][1] and have been baffled by the syntax of some of his function calls. Admittedly it's been a while since did C at uni but I've never encountered untyped function arguments like this:

find_path(start,end,parents)
int start;
int end;
int parents[];
{
if ((start == end) || (end == -1))
printf("\n%d",start);
else {
find_path(starts,parents[end],parents);
printf(" %d",end);
}
}
Is this valid syntax anymore? Are / were there any benefits with this style of function declaration? It seems more verbose than the conventional inline typing of arguments.

[1]:

[To see links please register here]

"netflow.c"
Reply

#2
They are called K&R style definitions. Don't use them in new code. Even K and R recommend that you stay away from them in "The C Programming Language 2ed".

> A note of history: the biggest change between ANSI C and earlier
> versions is how functions are declared and defined.
>
> The parameters are named between the parentheses, and their types are
> declared before opening the left brace; undeclared parameters are
> taken as `int`.
>
> The new syntax of function prototypes makes it much easier for a
> compiler to detect errors in the number of arguments or their types.
> The old style of declaration and definition still works in ANSI C, at
> least for a transition period, but **we strongly recommend that you use
> the new form when you have a compiler that supports it**.
Reply

#3
This is an old style way of giving the function types. It was dropped in the [C99 standard][1] and is not appropriate for modern code.


[1]:

[To see links please register here]

Reply

#4
These K&R definitions are the historically traditional way to define functions. In the original C this was the only way to define a function.

Don't use K&R definitions any more. Why not? Because doing so stops the compiler being able to check for type mismatches.
Reply

#5
The arguments are typed, just not inline. The types are between the first line and the opening bracket.

Anyway, this style is old and not recommended.
Reply

#6
This old syntax stems from the typeless [B programming language][B] (and as others stated, is not in standard C anymore):

printn(n,b) {
extrn putchar;
auto a;

if(a=n/b) /* assignment, not test for equality */
printn(a, b); /* recursive */
putchar(n%b + '0');
}


By the way, some compilers may offer a flag that let you compile this oldstyle K+R code.


[B]:

[To see links please register here]

"Users' Reference to B"
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through