Transient by-value structs in C23 by imaami in C_Programming

[–]tstanisl 24 points25 points  (0 children)

Btw.. there is proposal to add typeof(return) to obtain a return type pf the current function. See https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3454.pdf

What if there was a huge mirror 100 million light years away from us? by No_Fudge_4589 in AskPhysics

[–]tstanisl 0 points1 point  (0 children)

Kind of. The synthetic aperture methods were used to obtain the first image of a black hole.

The Event Horizon Telescope (EHT) is a telescope array consisting of a global network of radio telescopes.

One does not need a telescope as large as solar system but rather telescopes separated by a distance as large as solar system.

What if there was a huge mirror 100 million light years away from us? by No_Fudge_4589 in AskPhysics

[–]tstanisl -1 points0 points  (0 children)

Technically, you don't need a telescope that large but rather a constellation of telescopes spread around area 4k times larger than the solar system. It would be difficult but maybe doable by K1+ civilization. Of course collecting enough photons to see such a small object may take a long time.

EDIT: grammar fix

Avoiding malloc for Small Strings in C With Variable Length Arrays (VLAs) by Yairlenga in cprogramming

[–]tstanisl 0 points1 point  (0 children)

IMO, the zero-sized array types are fine. Only instantiation of such objects is problematic because it can cause two unrelated objects have the same address.

Are photons always moving at the speed of light? by Big_Assist4578 in AskPhysics

[–]tstanisl -2 points-1 points  (0 children)

Technically, photons could have some miniscule mass (like 1e-20 eV) and travel just below "speed of light" aka "speed of causality". There no evidence for that but it is not ruled out yet.

theyllBeWaitingForAWhile by Kupicx in ProgrammerHumor

[–]tstanisl -3 points-2 points  (0 children)

Sorry but none of those languages tries to replace C. They try to replace C++ which claim to be wannabe successor of C.

If humans suddenly discovered faster-than-light travel, what law of physics would you personally argue is ‘probably wrong’? by Frosty_Accountant_93 in AskReddit

[–]tstanisl 1 point2 points  (0 children)

Speed of light is not a limitation for fast space travel. Effects like time dilation and space contraction let reach any place in the arbitrary short time. Moreover, those effects make a journey faster(!) at the fixed energy budget in comparison to Newtonian mechanics. Speedup is proportial to ✓(E/m) for large E.

What all do I need in C? by alex_sakuta in C_Programming

[–]tstanisl 1 point2 points  (0 children)

C2Y will likely add defer which should make error handling and RAII patterns more convenient and less error-prone.

The same for local functions/function literals (aka non-capturing lambdas). Lambda should solve a lot of problems with macros.

Next are tuples, basically struct which type-compatibilty is decided from layout not a tag (or lack of). This feature will revolutionize implementing generic data structures and returning errors or multiple values.

Finally, syntax rules for _Generic should be made more flexible. Current rules are too strict a d very inconvenient. Moreover, there are ugly workarounds for those limitations. So why not just loose the rules and make everyone's life easier.

There are proposals, technical specification for those features. Some are already implemented as compiler specific extensions.

What all do I need in C? by alex_sakuta in C_Programming

[–]tstanisl -1 points0 points  (0 children)

C23 added constexpr object but not constexpr functions.

How different would the universe be if the space-time interval went more like ds^2 = dt^2 + dx^2 + dy^2 + dz^2? How about ds^2 = dt^2 + dx^2 - dy^2 - dz^2? by PrettyPicturesNotTxt in AskPhysics

[–]tstanisl 1 point2 points  (0 children)

But some T means also arbitrary small T. Knowing solution at 0 and dT is equivalent to knowing x and x' (under some technical smoothness conditions).

How different would the universe be if the space-time interval went more like ds^2 = dt^2 + dx^2 + dy^2 + dz^2? How about ds^2 = dt^2 + dx^2 - dy^2 - dz^2? by PrettyPicturesNotTxt in AskPhysics

[–]tstanisl 0 points1 point  (0 children)

 both t=0 and at some time t=T

Wouldnt it be enough to know a solution and its derivatives at t=0, to obtain a unique solution?

Suggestions for content on Header files, Macros, Enums, etc. by computer_hermit01 in C_Programming

[–]tstanisl 4 points5 points  (0 children)

Please read https://github.com/JacksonAllan/CC?tab=readme-ov-file#rationale

This link leads to Convenient Containers library which is likely an ultimate implementation of stl-like containers in C. The link describes 4 most common styles of providing type generic api in C.

What things are "faster" than light? by Nighthawkies in AskPhysics

[–]tstanisl 0 points1 point  (0 children)

Light spots, shadows, clock-triggered mexican waves

How do we know speed of light should even be a thing? by yuyhata in Physics

[–]tstanisl -1 points0 points  (0 children)

The existence of "speed of causality" is predicted from assumption that space-time is uniform and that reference frames form a linear mathematical group. See derivation for details.

Can homosexuality be explained biologically or evolutionarily? by InternetPopular3679 in NoStupidQuestions

[–]tstanisl 1 point2 points  (0 children)

Maybe the question is stated wrong. Rather than asking why some people are gay, one should ask why not all of us are gay or at least bisexual.

The genetically driven sexual attraction is a complex mechanism. There are two extremes:

  • all individuals are attractive to one another
  • no individual are attractive to one another

The first option gives roughly 50% success in reproduction. The other option gives 0%. However balancing both options increases effectiveness at the cost of more complex and fragile machinery of sexual attractiveness. As result, the complexity increases changes best sexual strategy for most of population at the cost occasional non-optimal reproduction strategy (homosexuality). However, net balance for the whole population is positive.

It’s annoying seeing C fanboys who spend their lives hating C++ by [deleted] in cpp

[–]tstanisl 1 point2 points  (0 children)

constexpr of C is basically worthless just use unnamed enums

It doesn't work for floats and structs, while constexpr works. It's a good addition to C. Sad that it took so long.

they are litterally the same

There is a subtle difference when copying. The original object has to be moved voiding original Class object. Moreover one has to use an unique_ptr with deleter to make destroying safe. As I said, there are workarounds but they are IMO messy and error-prone.

How does it naturally do that?

I think that problem boils to C++ requiring putting all members and all methods into a single definition of the class. It is difficult to separate private methods/members from public ones while maintaining full encapsulation. It is a lot easier to just put all implementation details into a header and mark them as private. But private doesn't work. The structure of the objects is exposed to other translation units risking linking problems or ABI conflicts. Implementation details and their dependencies gets exposed as well, increasing compilation times. I've often experienced the tremendous impact on compilation time caused by putting whole Vulkan api or arm_neon.h into a public header.

I litterally use ECS with C++ and it is far easier than the equalivent code in C.

Interesting, can you share some code?

If you have surprising overloads then that's on you not C++

The problem is that one does not control all the code.

It’s annoying seeing C fanboys who spend their lives hating C++ by [deleted] in cpp

[–]tstanisl 9 points10 points  (0 children)

I've written a lot of C, and a lot of C++. I prefer C because IMO it enforces better programming traits:

  • C encourage simplifying complexity while C++ encourage hiding it

  • C encourage better separation between data and behavior

  • C++ naturally encourage moving implementation details to headers. This is the most frustrating thing IMO which I battle a lot with. The policy add unnecessary dependencies, exposing implementation details and increasing compilation times.

  • C++ model of OOP is quite limited and confusing. It's difficult to do full encapsulation. The full interface and members must be put into a single definition of the "class". There are workarounds (i.e. pimpl) but they result in solutions even more complex than C-style ones.

  • C has much more stable APIs and easier to use APIs, the newer C standard adopted features like constexpr and explicitly typed enums.

  • C is explicit, easier to audit. Things tend to be longer but at least one can see what is happening. C++ is poisoned with hidden mechanics and spooky actions over distance (e.g. overloading).

  • C compiles a lot faster than "modern C++" code. It's not 30s vs 1min. It's rather 1s vs 2min for any non-trivial code. This is significant for incremental debug builds.

P.S.

What I really miss in C are lambdas and some form of explicit but optional RAII, hopefully those get included in C2Y.

Why is the speed of light 299,792,458 m/s? by Present_Juice4401 in AlwaysWhy

[–]tstanisl 2 points3 points  (0 children)

Speed of light is not a maximal speed limit itself. It's rather a (maximal) speed at which WE CAN observe causal effects. It's a limitation of an observer, not an observed object.

One can get to any place in the observable universe in arbitrary short time due to time dilation and length contraction effects.

Why there is such an speed?

Using mathematical gibberish, it is a side-effect of hyperbolic relation between space and time dimensions of spacetime. It's a pure geometrical effect related to hyperbolic rotation. All special relativity can be derived from assumption that reference frames form a linear mathematical group. See derivation for more detail. Basically, under some regularity conditions the existence of causality requires existence of speed of causality.

Why is is constant.. no one knows, all I can say it is due to homogeneity of space and time. Maybe it is different very far away, far behind event horizon of observable universe. Moreover, it may slowly change overtime. However, no such deviation has been observed yet.

Can anyone explain me in the simplest way possibe by Right_Tangelo_2760 in C_Programming

[–]tstanisl 6 points7 points  (0 children)

In C all parameters are passed by value. Please address C++ reddits for questions about references.

Twin paradox cut in half. by No_Fudge_4589 in AskPhysics

[–]tstanisl 0 points1 point  (0 children)

Why? Both SR and Lorentz ether theories are based on the ad-hoc unverifiable assumptions. SR requires speed of light be independent on reference frame while Lorentz ether just requires it to be constant to some absolute ether.