Function to Function Pointer refactoring

Last week I had some time to work on some C legacy code again and write some unit tests. I've been playing with a refactoring that I've used in the past and now use it all the time when working in C. The refactoring is called "function to function pointer" and is fairly trivial to do and save in legacy code. It gives a lot of flexibility.

The steps are:

  1. Change function prototype to function pointer in the header (just adding (*name)). Make sure it's extern
  2. Rename the function in the .c file to name_impl, or something non conflicting.
  3. At the end of the .c file. Initialize the function pointer with the _impl one.

That's it. Just takes a few seconds and it allows you to dynamically replace the function in your unit tests. It makes unit testing code in C a lot easier. (there are also some variants, but this is the easiest and most basic version)

Read more

Vibe Coding

Vibe Coding

สร้างผลงานในจังหวะของ AI Web Summit 2025 — Lisbon | Matt Wolfe, Replit ลองจินตนาการดูว่า… การเขียนโค้ดของคุณไม่ได้เหมือนกับพิมพ์คำสั่งในเทอร์มินัล แต่เหมือนกับ เล่นดนตรีร่วมกับวง — มีจังหวะ มีความรู้สึก และมีคู่หูที่เข้

By Chokchai
เอื้อมไปคว้าดาว

เอื้อมไปคว้าดาว

หลายคนอยากประสบความสำเร็จ องค์ประกอบที่สำคัญที่จะทำให้เราประสบความสำเร็จได้นั้น คือการที่เราสามารถสร้างผลงานที่มีคุณภาพสูงออกมาได้อย่างสม่ำเสมอ ไม่ใช่สร้างได้แค่เป็นครั้งคราวนะ ลูกฟลุ๊คแบบนั้นเพียงพอแค่สำหรับมือสมัครเล่น ถ้าจะเลี้ยงปากท้องยึดเอาเป็นอาชีพได้ เราต้องสร้างผลงานคุ

By Chokchai