Elektrine lite

← Feed

@teilweise@layer8.space

Post #1758319

2026-04-20 15:25 UTC

@leeloo @Sarnau @mayo @dasdom Do you know the difference between 'const char *` and `char * const` in C++? I think `let` is a more like `char * const` than like `const char *`. The `"\("string literal")"` case probably gets special treatment when optimizing. I vaguely remember it from when I implemented https://github.com/dhoepfl/DHLocalizedString/ because it was concatenated even when I wanted to get *every* interpolation but could not. Not to forget: Interpolation is used for more than just plain old strings.

Replies (1)

  • @leeloo@c.im 2026-04-20 15:43

    @teilweise @Sarnau @mayo @dasdom I don't remember which is which, but in one case you can change the value, and in the other you can change it to point to a different string. Neither of which is allowed in Swift. Besides, Swift strings are supposed to be (copy on write) value types, so not comparable to a pointer anyway. Your comparison fits pretty well for classes, though. Unless you use @ mutating as intended. My point was that a const is supposed to be treated exactly like a literal (where semantically equivalent), otherwise it still loses out to plain old nasty # define. Swift let is so much more than const, but is supposed to replace const in the simple cases. (C# goes the other way and adds the "readonly" keyword where a true const is not possible).

    Open ##1758320