_Generic keyword support in C11

_Generic keyword support in C11

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[i])

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

5 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Nice to hear that.

 

Thanks.

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

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

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

Accedere per lasciare un commento.