Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Search - "extern"
-
There is a Linux based os called extern OS.....man....shit looks so pretty and its scriptable through js for deektop apps and shit. Should be pretty interesting11
-
Annoyance in C: using the same keyword for two unrelated things, process-long memory allocation and internal linkage. Looking at you, static.
The latter should really have been called "intern", just like there is "extern". Far more people would use it if it was named correctly.
History says "static" was chosen for compatibility, allowing older compilers to take new source files.2 -
Whenever anyone asks me why I dislike C++ I'm just going to point to this current app I'm working. Had a unit test with an extern method declaration that had 7 or 8 different parameters. No big. Problem is that the ACTUAL definition of the method had 1 less parameter than the extern declaration. It worked perfectly fine in x86. Ported to x64, compiled fine, hard crash at runtime. Debugger not a super lot of help. Took me a couple days to figure that one out. Also I am broke so I can't even drink the pain away. Neat.
-
"Reflective" programming...
In almost every other language:
1. obj.GetType().GetProperties()
or
for k, v in pairs(obj) do something end
or
fieldnames(typeof(obj))
or
Object.entries(obj)
2. Enjoy.
In C++: 💀
1. Use the extern keyword to trick compilers into believing some fake objects of your chosen type actually exist.
2. Use the famous C++ type loophole or structured binding to extract fields from your fake objects.
3. Figure out a way to suppress those annoying compiler warnings that were generated because of your how much of a bad practice your code is.
4. Extract type and field names from strings generated by compiler magic (__PRETTY_FUNCTION__, __FUNCSIG__) or from the extremely new feature std::source_location (people hate you because their Windows XP compilers can't handle your code)
5. Realize your code still does not work for classes that have private or protected fields.
6. Decide it's time to become a language lawyer and make OOPers angry by breaking encapsulation and stealing private fields from their classes using explicit template instantiation
7. Realize your code will never work outside of MSVC, GCC or CLANG and will always be reliant on undefined behaviors.
8. Live forever in doubt and fear that new changes to the compiler magic you abused will one day break your code.
9. SUFFER IN HELL as you start getting 5000 lines worth of template errors after switching to a new compiler.13 -
Spent a good part of a year developing some complex software in C for my employer only to find our environment supports C++; all I had to do was drop in a handy dandy "extern c". But why...
-
The most normal C++ program be like:
// prints "Hello, World!"
namespace{decltype(+*"")(*main)()=[]()->decltype(main()){return{};};}
decltype(main())(main(decltype(main())={},decltype(&*"")_[]={})){
extern decltype(&"") puts;
reinterpret_cast<decltype(::main())(*)(decltype(&*""))>(&puts)("Hello, World!");
return(decltype(::main()){});
}8 -
me: wanting a clean table to work, the less stuff the better, best would be a single notebook and nothing else
also me: backend dev, so 3 monitors, extern keyboard and mouse, some documentation papers and oh where is this cup coffee of last week coming from?