Interesting str_len() by DJB
3 posts
• Page 1 of 1
Interesting str_len() by DJB
It is about 1 am here. Bored out of my mind perusing through some source code written by the greatest computer scientist alive today. I ran across Daniel Bernstein's str_len() function. For those unfamiliar, it is written in C.
- Code: Select all
unsigned int str_len(const char *s)
{
register const char *t;
t = s;
for (;;) {
if (!*t) return t - s; ++t;
if (!*t) return t - s; ++t;
if (!*t) return t - s; ++t;
if (!*t) return t - s; ++t;
}
}
Has to be hands down the most interesting approach I have ever seen. I spent a good 10 minutes in awe on this one. This guy is what I like to call an "out of the box" thinker. This function was included in his daemontools package with filename str_len.c
Daniel J Bernstein (DJB) is the author of qmail and many other very secure *nix packages. If you want to check out more of his work, head on over to http://cr.yp.to
-Weaver
Public Keys
The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
- Weaver
- PROfessional Member
- Posts: 1967
- Joined: Wed Jun 19, 2002 12:05 am
- Location: /home/weaver/
if i could only understand what it was saying so i could sit and stare in awe too. weaver, is there any end to your knowledge, it seems that you know the answer to all of the technical questions
- imnuts
- Posts: 7457
- Joined: Wed Mar 24, 2004 5:19 am
- Location: Boothwyn, Pennsylvania
- Real Name: Mark
imnuts wrote:if i could only understand what it was saying so i could sit and stare in awe too. weaver, is there any end to your knowledge, it seems that you know the answer to all of the technical questions
I wish my knowledge basin was an abyss. In the computer science and information technology (I hate the word IT) realm I try to be very well rounded. Move out of that realm and its related topics (Mathematics, Physics) and you'll find that I am quite disabled. My better half (who also happens to be my roommate) is studying nursing. Her chemistry and biology knowledge is amazing, I find myself trying to learn what she is doing but just cannot seem to hold the information.
My advice is first and foremost to read a lot. You don't have to read novels, but pick up technical literature that you find interesting. Read slashdot, browse at a threshhold of at least 3. Slashdot can be a double edge sword, so take what you read with a grain of salt.
The most important thing you can do is be motivated and excited to learn. If you are not excited by your major/career, pick a new one. You will never be an expert if you do not go beyond what is asked and required. The most important skill to have is fundamentals. You may say cliche, but for being cliche I don't see too many people who have their fundamentals down.
You have to know the basics, and know them well. If you don't, high levels of abstraction and abstracted concepts all seem like magic. You need to understand the foundation, without it you can still succeed, but by the seat of your pants. Sooner or later you will be confronted and put in your place.
-Weaver
Public Keys
The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form of the constant. This also simplifies modifying the program, should the value of pi change.
-- FORTRAN manual for Xerox Computers
- Weaver
- PROfessional Member
- Posts: 1967
- Joined: Wed Jun 19, 2002 12:05 am
- Location: /home/weaver/
3 posts
• Page 1 of 1
Return to HTML, CSS, and Scripts
Who is online
Users browsing this forum: No registered users and 4 guests