Question

Given a C function:

void f(T x, T y) {
    x = y;
}

I want to make sure that all instances of T assignments will fail. So far, the best solution I have is something like:

#define T const void *

is there a better solution? (Ideally I would like T to be defined as some kind of a non-assignable opaque record pointer type).

Était-ce utile?

La solution

typedef is more suitable here.

For immutable data: typedef const void * T;

For immutable pointer: typedef void * const T;

Autres conseils

I made a dumb mistake. Apparently,

typedef const int T 

or

typedef void * const T

work fine for preventing the assignment.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top