Writing some tests...
Writing some tests...
I wonder if anyone has seriously thought about adding some kind of namespacing to the C preprocessor.
for example, it would be nice if you could say
#namespace FOO
#include "foo.h"
#endnamespace
and then all the preprocessor defines from foo.h are brought into your file with names like FOO###BOOL
I keep coming back to #ObjectiveC, but I feel that parts of the way an #ObjC #preprocessor (as it was) builds classes is similar to how #ctran worked/works for #Psion OO C.
I wonder if looking at ObjC #compiler internals would help me? Something like this:
https://alwaysprocessing.blog/2023/01/02/objc-class-arch
Or, as I keep saying with this project, is it much simpler than I'm trying to make it?
Class-building time for #ctran.
The compiler tutorials I've read don't talk about how to deal with classes and inheritance. I assume that a metaclass has to be built for each class. But should I then store those metaclasses for later use, or do I regenerate them when needed? I assume the former.
Also, my parser doesn't currently check for duplicate classes or methods (inside classes). Should it be in the parser, or should it be part of the thing that builds the output?
STM32. Процесс компиляции и сборки прошивки
Многие из начинающих разработчиков софта для микроконтроллеров реализуют свои проекты исключительно в средствах разработки, которые предоставляются производителем. Многое скрыто от пользователя и очень хорошо скрыто, из-за чего некоторые воспринимают эти процессы сродни настоящей магии. Я, в свою очередь, как человек в пытливым умом и природной любознательностью, решил попробовать собрать проект без использования IDE и различного рода автоматизаций. Так родилась идея для этой статьи: не используя ничего, кроме текстового редактора и командной строки, собрать проект мигания светодиодом на отладочной плате STM32F0-Discovery. Поскольку я не до конца понимал, как происходит процесс компиляции и сборки проекта, мне пришлось восполнять пробелы в знаниях. Разобравшись с этим вопросом, я подумал — а почему бы не рассказать другим об этом? Всем кому интересно — добро пожаловать под кат!
Sometimes there's a need to compile certain part of the code depending of the external factors like target OS or whether it's debug or release build. There is preprocessor directive #if that allows to wrap a part of the code the be conditionally compiled but there are certain disadvantages to using that:
compiler doesn't check the code that is inside #if directive when the condition is not true. That could lead to discovering an error once the directive changes to true due to other part of the system had changed.
with #if it's often that the directive would be inside the method at the call site, mixed up with the generic code which makes that harder to read
Conditional attribute can fix those problems. We only need to mark the method that supposed to be conditionally compiled into the code. We do not need to change the call-site and the compiler takes care of that. Also, the compiler still checks the correctness of the code that we have inside that method.
Docs for preprocessor directives
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#conditional-compilation
Docs for Conditional attribute
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.conditionalattribute?view=net-8.0
Did you had to use those in your projects? If so please share .
ICYMI: My first thoughts on #Psion's dialect of Object Oriented C for the Series 3 and related portable computers.
Includes the JPI/Clarion TopSpeed compiler, a proprietary preprocessor, the Eiffel programming language, and a handful of calling conventions.
Also, did somebody say Objective-C?
Linux Fu: Preprocessing Beyond Code https://hackaday.com/2023/12/28/linux-fu-preprocessing-beyond-code/ #HackadayColumns #preprocessor #LinuxHacks #linux #m4
Linux Fu: Preprocessing Beyond Code https://hackaday.com/2023/12/28/linux-fu-preprocessing-beyond-code/ #HackadayColumns #preprocessor #LinuxHacks #linux #m4
Linux Fu: Preprocessing Beyond Code - If you glanced at the title and thought, “I don’t care — I don’t write C code,” th... - https://hackaday.com/2023/12/28/linux-fu-preprocessing-beyond-code/ #hackadaycolumns #preprocessor #linuxhacks #linux #m4
@jhx You asked for it, so I'll answer it:
Imho, C++ design is broken from the very beginning. It wanted to provide #OOP language constructs, still maintaining full #C compatibility (which already failed many years ago, cause the languages took different roads).
It combines #exceptions (IMHO generally a bad idea) with explicit resource management (an *awful* idea, forcing you to use #RAII which will in turn mandates creation of purely "technical" classes, just to manage resources).
It wanted #generics, but that's impossible without breaking C compatibility, so it came up with #templates, actually a #preprocessor on steroids.
Overloading also doesn't fit into the simple C library ABI (where #linker symbols are named just like the function), so it came up with "name mangling" ... which is especially horrific because it is *not* standardized.
Ah well, I could go on