Skip to content

Commit a09a51b

Browse files
committed
implemented const_cast as a macro
1 parent 5bbc4d5 commit a09a51b

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/fread.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,11 @@ static void Field(FieldParseContext *ctx);
126126
//=================================================================================================
127127

128128
/**
129-
* Drops `const` qualifier from a `const char*` variable, equivalent of
130-
* `const_cast<char*>` in C++.
129+
* Drops `const` qualifier from any scalar object, equivalent of
130+
* `const_cast` in C++.
131131
*/
132-
static char* const_cast(const char *ptr) {
133-
union { const char *a; char *b; } tmp = { ptr };
134-
return tmp.b;
135-
}
132+
#define const_cast(x) (((union{typeof(x) a; typeof(+(*(x)))* b;}){.a=(x)}).b)
133+
136134

137135
/**
138136
* Free any resources / memory buffers allocated by the fread() function, and

0 commit comments

Comments
 (0)