Syntax question - *(*new)

Hello,
My question is about new syntax introduced in c/cpp standards. Recently I have encountered such syntax:

ssh_cipher *(*new)(const ssh_cipheralg *alg);

The above declaration relates to c standards. What does it means and how write it in cpp?

Best regards,
JK
 
ssh_cipher* (* new) (const ssh_cipheralg *alg);

It's a C statement defining a function pointer variable called 'new'.
It's a strange syntax, but that's how it's done in C.

In C++ you can do it the same way, but since 'new' is a keyword in C++, you would need to change the name of the variable. Or better yet, you could use std::function.

 
std::function<ssh_cipher*(const ssh_cipheralg*)> ssh_new;

new is a function pointer to a function that returns an 'ssh_cipher *' and accepts a single parameter of type 'const ssh_cpheralg *'.

Other than the use of a reserved keyword, the code is valid C++. To make it valid it could be rewritten as
ssh_cipher *(*new_function)(const ssh_cipheralg *alg);
Hello,

many thanks for explanation.
I thought that it is new syntax in c standards.

Best regards,
JK
Topic archived. No new replies allowed.