Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/fread.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ static void Field(FieldParseContext *ctx);
//=================================================================================================

/**
* Drops `const` qualifier from a `const char*` variable, equivalent of
* `const_cast<char*>` in C++.
* Drops `const` qualifier from any scalar object, equivalent of
* `const_cast` in C++.
*/
static char* const_cast(const char *ptr) {
union { const char *a; char *b; } tmp = { ptr };
return tmp.b;
}
#define const_cast(x) (((union{typeof(x) a; typeof(+(*(x)))* b;}){.a=(x)}).b)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the issue titled 'awful one liners don't improve readability or performance' (#6995) I see you wrote:

Collapsing everything into one line doesn't make the code run faster, the compiler is smart enough to sort it out.

I wonder what category this belongs to then 🤔

Copy link
Contributor Author

@badasahog badasahog Jun 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fair criticism!

The problem is, I don't think it's even possible to implement it differently since its a macro, and I think const_cast already has a clear enough meaning that the one liner isn't too bad here. It's clear what the code does.



/**
* Free any resources / memory buffers allocated by the fread() function, and
Expand Down
Loading