Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

_Generic keyword support in C11

velvia
Beginner
498 Views

Hi,

The _Generic keyword is a C11 feature that does not seem available in Intel compilers. It would allow better implementation of object-oriented code in C. Do you plan to support it in the next releases ?

typedef struct {
	int size;
	double *data;
} VectorDouble;
typedef struct {
	int size;
	int *data;
} VectorInt;

#define alloc(a, n) _Generic((a), VectorDouble: alloc_VectorDouble(&a, n), VectorInt: alloc_VectorInt(&a, n))
#define release(a) _Generic((a), VectorDouble: release_VectorDouble(a), VectorInt: release_VectorInt(a))
#define at(a, i) _Generic((a), VectorDouble: a.data)

void alloc_VectorDouble(VectorDouble *a, int n) {
	a->data = (double*) malloc(n * sizeof(double));
}

void free_VectorDouble(VectorDouble a) {
	free(a.data);
}

void alloc_VectorInt(VectorInt *a, int n) {
	a->data = (int*) malloc(n * sizeof(int));
}

void free_VectorInt(VectorInt a) {
	free(a.data);
}
int main (int argc, char const *argv[])
{
	const int n = 8;

	VectorDouble a;
	VectorDouble b;
	VectorDouble c;

	alloc(a, n);
	alloc(b, n);
	alloc(c, n);
		
	for(int j = 0; j < n; ++j)
	{
		at(a, j) = at(b, j) + at(c, j);
	}

	release(a);
	release(b);
	release(c);

	return 0;
}

 

 

Best regards,

Francois

0 Kudos
4 Replies
velvia
Beginner
498 Views

Nice to hear that.

 

Thanks.

0 Kudos
Kittur_G_Intel
Employee
498 Views

Thanks Melanie, I've noted the tracker id and will update this post as and when the release with the fix is out.  Velvia, appreciate your patience till then

_Kittur

0 Kudos
Melanie_B_Intel
Employee
498 Views

Regretfully, I have to report that DPD200250282 is not on track for the next major release. I'll modify/delete my previous post. Best, Melanie

0 Kudos
Kittur_G_Intel
Employee
498 Views

Hi Velvia,

Since the feature support will not be in the next major release you will have to try to work on your OOP without the __generic keyword for now :-( I'll keep you updated as and when the support with the release is out. Appreciate your patience till then.

_Kittur

0 Kudos
Reply