What is this

P

Priya Mishra

Hi all,

I am new to C++, so please help me in understanding the below code as
I am not able to
understand, Is this a another way to write the function in C++, and if
yes the any advantage ?

void Update (ctext, input, inputLen)
M_C *ctext; char *input;
unsigned int inputLen;
{
// do some stuff
}


Please Ignore me as I know C.

Thanks
Priya
 
M

Marcus Kwok

Priya Mishra said:
I am new to C++, so please help me in understanding the below code as
I am not able to
understand, Is this a another way to write the function in C++, and if
yes the any advantage ?

void Update (ctext, input, inputLen)
M_C *ctext; char *input;
unsigned int inputLen;
{
// do some stuff
}

This is the old-style (I think it may be called K&R style) C way to
define a function. IIRC it is not allowed in C++. The equivalent C++
definition should be:

void Update(M_C* ctext, char* input, unsigned int inputLen)
{
// do some stuff
}
 
V

Victor Bazarov

Priya said:
I am new to C++, so please help me in understanding the below code as
I am not able to
understand, Is this a another way to write the function in C++, and if
yes the any advantage ?

void Update (ctext, input, inputLen)
M_C *ctext; char *input;
unsigned int inputLen;
{
// do some stuff
}

This is a very old (and as such non-standard) way of defining a function.
It wasn never part of C++. It was at some point part of C, and IIRC, it
was K&R C. By the time C was standardised this form was replaced with
the full declaration of the arguments between the parentheses.
Please Ignore me as I know C.

Huh??

V
 
D

Default User

Victor said:
Priya Mishra wrote:

This is a very old (and as such non-standard) way of defining a
function. It wasn never part of C++. It was at some point part of
C, and IIRC, it was K&R C. By the time C was standardised this form
was replaced with the full declaration of the arguments between the
parentheses.

The old-style function definitions are still part of C, although
deprecated. From the C99 draft standard:

6.11.5 Function definitions

[#1] The use of function definitions with separate parameter
identifier and declaration lists (not prototype-format
parameter type and identifier declarators) is an obsolescent
feature.


Basically it's retained due to the tons of legacy code using this
definition style. No new C code should be done that way. C++, as you
say, never had it in a standard version, and I don't if any compilers
supported it in the pre-standard days.




Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top