Use the new standards-conformant preprocessor with `/Zc:preprocessor`
https://learn.microsoft.com/en-us/cpp/build/reference/zc-pre...
HN user
blog: https://www.davidpriver.com
Use the new standards-conformant preprocessor with `/Zc:preprocessor`
https://learn.microsoft.com/en-us/cpp/build/reference/zc-pre...
Pascal strings might be the only string design worse than C strings. C Strings at least let you take a zero copy substring of the tail. Pascal strings require a copy for any substring! Strings should be two machine words - length + pointer (aka what is commonly called a string view). This is no different than any other array view. Strings are not a special case.
The world won’t allow a dependence on a single geopolitically threatened entity in the long run, so either they defuse that risk themselves or risk a competitor filling that role. This move is better for TSMC itself.
If you want to remain portable, write your code in the intersection of the big 3 - GCC, Clang and MSVC - and you’ll be good enough. Other implementations will either be weird enough that many things you’d expect to work won’t or are forced to copy what those 3 do anyway.
You can apply `#` to __VA_ARGS__, which won’t preserve the exact whitespace, but for many languages it’s good enough. biggest issue is you can’t have `#` in the text.
I wrote a similar article in the past: https://www.davidpriver.com/ctemplates.html
I use this technique in my hobby projects as it has worked out the best for me of the options I’ve explored.
Works with MSVC if you add /Zc:preprocessor (to get a standard compliant preprocessor instead of the legacy one).
The author relies on the compiler fitting the bitfield in unused padding bytes after “speed”, but that is implementation-defined behavior (almost everything about bitfields is implementation defined). MSVC will align the unsigned bitfield to alignof(unsigned), whereas GCC and clang will use the padding bytes. To portably pack the struct, use unsigned integers and use flags (monster.flags & CAN_FLY instead of monster.can_fly).
C23 has _Float16
Summer reading programs are a band-aid on the problem that children shouldn’t have such a long summer break now that air conditioning is common. Spread the breaks out throughout the year if you want to maintain the same number of days off. All evidence shows the summer break is bad for children’s academic achievement (especially poor children), but it is viewed as a perk for the teachers so the teacher’s unions fight against questioning it.
We immediately began disclosure of this issue once we realized the potential impact. Unfortunately, no disclosure contacts were publicly available and we had to resort to emailing random people. The Paradox.ai security page just says that we do not have to worry about security!
Amazing.
The “typeof on old compilers” section contains the code:
(list)->payload = (item); /* just for type checking */\
That is not a no-op. That is overwriting the list head with your (item). Did you mean to wrap it in an `if(0)`?In D, you can just do a static foreach over a sequence to generate case labels:
Don’t ignore food addiction, the app turns into a button you can press on your phone and in a bit you’ll have a dopamine hit from the food. You don’t have to get dressed or confront the reality of your situation.
That’s not the point of hello world. It’s not to be as small a valid program as possible. It’s to be a small program that also exercises the needed functionality for using the tool usefully. All of the exercises following that hello world need formatted text, so introducing puts would just add confusion and wouldn’t verify that you have a working printf.
Tabs are a control character and have no business being in a text file. Do you use ascii record separator characters too?
You’re switching to the build system of a different, pre 1.0 programming language that has frequent breaking changes?
This does actually look a lot better. Using the inspector to toggle it on and off, “pretty” does look a lot prettier.
Backslash is a valid path character (you can use / or \ as the path separator on windows) so if the backslash isn’t actually escaping anything it is left as-is.
let not thy left hand know what thy right hand doeth
If you’re interested in this, I wrote a blogpost on a simple c hash table without deletion.
Without a non-linear activation function, chaining perceptrons together is equivalent to one large perceptron.
You can have methods with NamedTuple
I wrote a blogpost describing this technique. https://www.davidpriver.com/ctemplates.html
Somewhat a reference to https://wiki.c2.com/?ThreeStarProgrammer
Only msvc provides strcpy_s and they don’t conform to the standard. Other libcs don’t provide it. Ignore everything from Annex K and write your own wrappers around memcpy. You should always know the size of your buffers.
Use memcpy and do the size check yourself beforehand (taking the appropriate action if it doesn’t fit). Avoid any function starting with str except for strlen. Prefer pointer+length instead of relying on nul-terminated strings.
The correct thing to do is to use memcpy and to know the size of both the destination buffer and the source buffer. If the source buffer won’t fit, then you need to take an application-specific action (is truncation ok? do you have to abort the whole operation? Do you re-alloc the destination buffer? etc.) strncpy almost always does the wrong thing.
With a string literal it works, with a dynamic string it just gives an undefined reference error to eval.
I wrote a blogpost showing how you could do a similar thing in D with ImportC.