Reputation: 7902
Suppose we have many C functions with the same signature and return type:
R f(X x,Y y){...}
R g(X x,Y y){...}
R h(X x,Y y){...}
where X
and Y
are the types of the arguments and R
is the type of the result.
We can declare those functions, for instance in a header file or as forward declarations, like this:
R f(X,Y);R g(X,Y);R h(X,Y);
or more concisely:
R f(X,Y),g(X,Y),h(X,Y);
or, avoiding most repetition:
typedef R F(X,Y);
F f,g,h;
Can that be done in a single statement, without a separate typedef
?
Upvotes: 1
Views: 138
Reputation: 311088
I have not checked yet but maybe in C23 there is possible to write
typeof( R( X, Y ) ) f, g, h;
Upvotes: 1
Reputation: 39
head.h
#pragma once
int f(int, int), g(int, int), h(int, int);
head.c
#include "head.h"
int f(int x, int y) { return 0; }
int g(int x, int y) { return 0; }
int h(int x, int y) { return 0; }
main.c
#include <iostream>
#include "head.h"
int main()
{
f(1, 2);
return 0;
}
Upvotes: -1