your favorite function
Re: your favorite function
Great idea for a post. My favorite function is the one I've just written. Div_mod in ARM assembler.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: your favorite function
overall, sprintf. cout or printf are too limited as to where the information ends up, and that's not just the case for OS development.
Re: your favorite function
This is truly amazing how many people found this tread non pointless.(Sorry if this is a pointless thread)
I'll give you this one. Its very subjective. Physical memory allocation function for me. Everything will fall apart without it.your favorite function
Appears most in the source? Executed most by CPU? Most time consuming(longest name) to type?the function you use the most
Seriosly, which function can you remove and keep functionality of the kernel at the same level?could not live without
This is probably the first time time I regret that Combuster is no longer moderator. But since he is no longer with power he also decided to post while not having to say anything useful (my believe that thread is indeed pointless).
Re: your favorite function
umm.. in my kernel I have this file called `kdebug.c` which is nothing but special debugging functions. Among my most commonly used was `kputs_x_y` which would print a string at specified x and y coordinates without buffering. Also I used a thing called `stopints();hlt();` which would help me when debugging when getting page faults and other problems with printing to the screen and also I had a PANIC macro which was pretty amazing also lol
btw, this thread is pointless, but geppyfx isn't right.
btw, this thread is pointless, but geppyfx isn't right.
- NickJohnson
- Member
- Posts: 1249
- Joined: Tue Mar 24, 2009 8:11 pm
- Location: Sunnyvale, California
Re: your favorite function
For me, definitely signal() - my kernel function that sends a preemptive signal (16 byte synchronous message that changes control flow) to a process. It's used for not only all IPC, which in a microkernel is everything, but also IRQ handling, page fault handling, math emulation, and even efficient userspace threading. It's both the most complex system call and at the heart of other calls like fork() and exit(). It even uses itself for error handling. 57 well commented lines of awesome.
Re: your favorite function
Code: Select all
int main(int argc, char **argv)
Re: your favorite function
Code: Select all
#include <sstream>
#define SSTR( x ) dynamic_cast< std::ostringstream & >( ( std::ostringstream() << std::dec << x ) ).str()
This little piece of macro magic allows you to create that string on the fly using operator<<() without having to fumble around with ostringstream yourself. Especially useful with C-style log functions.
Example:
Code: Select all
call_to_foo( SSTR( "Output: a[1] is " << a[1] << ", and the answer to all questions is " << 42 ) );
Every good solution is obvious once you've found it.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: your favorite function
Even as a moderator, I would have let this run freely. In fact *you* would have been the more likely target for going offtopic.geppyfx wrote:This is probably the first time time I regret that Combuster is no longer moderator. But since he is no longer with power he also decided to post while not having to say anything useful (my believe that thread is indeed pointless).
If this thread was truly pointless, there would be nothing to learn. Do you know what the function Colonel Kernel mentioned does?
Re: your favorite function
I'm probably missing some C++ subtlety here, but what is the reason for casting ostringstream to ostringstream& ? I tried to compile with and without the cast. Without cast, it lead to the error "'struct std::basic_ostream<char, td::char_traits<char> >' has no member named 'str'" but I don't understand why the reference does have a member named 'str' and the struct itself doesn't.Solar wrote:Code: Select all
#include <sstream> #define SSTR( x ) dynamic_cast< std::ostringstream & >( ( std::ostringstream() << std::dec << x ) ).str()
Re: your favorite function
Just like me the first time around.Hobbes wrote:I'm probably missing some C++ subtlety here...
No such thing. There is some tricky type conversion going on....but what is the reason for casting ostringstream to ostringstream& ?
You need ostringstream& so you can call .str() at the end.
But you need ostream& so that e.g. char* is handled correctly (and not printed as a pointer value as it would with ostringstream&). That's why the operator<<( std::dec ) is in there - it works for ostringstream, and returns ostream&.
After you fed x to the ostream&, you have to convert it back to ostringstream& so you can call .str().
Ugly as all macros, but both valid and useful C++ code like all good macros. Tested on various platforms, too.
Every good solution is obvious once you've found it.
Re: your favorite function
Oh, and I forgot its trusted sidekick. Less impressive and convoluted, but just as useful.
Code: Select all
#define THROW( exc, code, message ) throw exc( SSTR( code << ": (" << __FLIE__ << ", line " << __LINE__ << ": " << message ) );
Last edited by Solar on Mon Nov 16, 2009 7:36 am, edited 1 time in total.
Every good solution is obvious once you've found it.
Re: your favorite function
Ah, silly me. The error message already told me. I overlooked the exact return type of operator<<(). Thanks!
Re: your favorite function
Does that mean sending messages is more important than memory allocations?Combuster wrote:geppyfx wrote:If this thread was truly pointless, there would be nothing to learn. Do you know what the function Colonel Kernel mentioned does?
Or do you suggest I learn ObjC? Maybe objc_msgSend is a macro or compiler/language related function? How come programming language related issues belong to osdev site not to mention "OS Development" forum(before it was moved).
It seems that all *you* can do is to argue about previously mentioned printf function. While the OP asks to present your own function.In fact *you* would have been the more likely target for going offtopic.
If we had a poll I'd give 1 vote to each of these: efficiently coded cli, kitchen_sink(), hack_the_gibson()overall, sprintf. cout or printf are too limited as to where the information ends up, and that's not just the case for OS development.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: your favorite function
must...not...feed...troll
I rest my case.
I rest my case.