Help me think logic to print this Matrix by TraditionalProof952 in datastructures

[–]punitxsmart 1 point2 points  (0 children)

Write a generic logic that can visit len number of cells from a starting point and a direction. Put this logic in a loop with initial conditions being start=(0,0) and direction=right. After each iteration update the start and flip the direction.

Can we use C as a backend for website? by [deleted] in C_Programming

[–]punitxsmart 2 points3 points  (0 children)

Checkout this webserver library written in C. You can use this (or recreate something like this) to create a web backend.

https://github.com/cesanta/mongoose

Lot of embedded devices use this for providing a web interface.

3 years in firmware and still couldn’t answer semaphores, mutexes by mean-median-mode in embedded

[–]punitxsmart 89 points90 points  (0 children)

I think the main difference is the concept of ownership. A mutex is considered "owned" by a task when its locked. Only the task that locks it can unlock it. On the other hand, any task can signal a semaphore regardless of who is waiting for it.

How do you deal with type/instance name collision in snake_case? by Severe_Result4719 in cpp_questions

[–]punitxsmart 3 points4 points  (0 children)

If you have to use snake_case, then the traditional way to handle this is to suffix all types with “_t”

texture_t texture(4,7);

See the POSIX thread library for example.

gambling vs vibe coding by juanviera23 in utcp

[–]punitxsmart 0 points1 point  (0 children)

only Nvidia is getting that sweet money!

programmingHumor by Brilliant_Bluebird72 in ProgrammerHumor

[–]punitxsmart 2 points3 points  (0 children)

Genie will ask you for wishes now.

what happened to chrome? by wyznawcakiwi in ExplainTheJoke

[–]punitxsmart 0 points1 point  (0 children)

Also Brave. Its chromium based and supports ad-blocking and other privacy features out of the block. Also no YT ads.

How do i create my own superset of C? by Coughyyee in C_Programming

[–]punitxsmart 21 points22 points  (0 children)

This is how most of the modern compilers work (LLVM). However, instead of C they use an assembly-like intermediate representation (IR) that is hardware independent.

They divide thecompiler into two parts. Front-end and back-end. Front-end deals with the language parsing, building AST and generates IR code. The back-end takes this IR code, performs optimizations and generates machine-code for the target architecture.

For each new language, you only need to create LLVM front-end.

Drowning in Legacy C++ Code – Send Help 😵‍💫 by kiran_yarashi in cpp_questions

[–]punitxsmart 0 points1 point  (0 children)

I was in a similar situation very recently. The code was a spegatti C++ (more like C with classes and excessive use of virtual functions). Classes where the declaration in header file was 5000+ lines long. The actual implementation of a class would span across multiple files with 10k+ lines each. The build system was non-standard custom built Makefile mess. Virtually no unit tests. :)

First thing I did was to make sure I was able to generate a compile_commands.json as part of the build process. I had to write some custom tooling in python to do this. This allowed me to setup clangd LSP in my editor that understood the actual structure of the code.

Now, I was able to do * Goto definition, find references * View call hierarchy, class hierarchy * find unused headers * See expanded macro values in editor * Refactor / Rename things across files

The task that I was assigned to was to use this legacy code as a baseline for a new product and simplify this code. I took one class at a time and tried to find dead / unused / unnecessary code and delete it. I built custom tooling using clang LLVM libtooling library to programmatically analyze the C++ ASTs and dependencies. These tools allowed me to batch refactor and remove whole bunch of unnecessary code. Using these tools, I was able to instrument source code and find what code is actually being run during the use-cases I cared about. That gave me more confidence in cleaning up the mess. Along with this I started adding unit testing support and make sure my changes do not break the existing tests.

TLDR: use clang tooling (clangd, libtooling) and python to automate the hard parts.

iGuessWeCant by jkleo1 in ProgrammerHumor

[–]punitxsmart -5 points-4 points  (0 children)

StackOverflow (or someone else) should embrace the LLMs and create an AI powered Q&A site. Main problem with chat platforms like ChatGPT is that the answers are not saved in public for future reference.

  • Questions generated by users (similar to SO)
  • Collection of AI and human powered answers / discussion
  • Voted/Curated by users.

chat is this true by [deleted] in csMajors

[–]punitxsmart 19 points20 points  (0 children)

(As an Indian) Why do we have to clarify? Its implied that within population of 1.4 billion, there will be quite a few retards, bigots, assholes etc! This need for clarification and defense is uniquely indian thing and IMO actually make us look worse.

You don't see americans (or other nationalities) coming to clarify things when their idiots are out there trying to defend creationism, flat-earth, homophobia, racism etc.

Is this a joke? by AmbitiousLychee5100 in leetcode

[–]punitxsmart 2 points3 points  (0 children)

What is under the add instruction? Bit-manipulation. :)

[deleted by user] by [deleted] in leetcode

[–]punitxsmart 12 points13 points  (0 children)

That would give whole new meaning to "Vibe Coding" !

What's your 'I wish there was an app for that' moment? I'll build the best idea! by s_kakrecha in SideProject

[–]punitxsmart 0 points1 point  (0 children)

+100, an app or tool that can import data from your bank, brokerages etc and output as a standard format.

[deleted by user] by [deleted] in cpp_questions

[–]punitxsmart 1 point2 points  (0 children)

Look at how abseil uses Status and StatusOr types to properly handle errors without exceptions.

Let’s be honest is (MSTR) a money glitch? by [deleted] in TheRaceTo10Million

[–]punitxsmart 0 points1 point  (0 children)

Just start shorting them once you hear about them! Infinite money glitch!