Nerds log.

Been pondering a lot of stuff.

I’ve especially been trying to learn more about stacks, queues, lists, and stuff. And it makes me wonder about things we take for granted.

Like arrays for example. How I see an array, at least from a C perspective — personally I think languages like Ruby. That have arrays that don’t need to be ‘re sized’ on command must have implemented arrays in the language. As objects acline to a doubly linked list.

Generally (C like) when I look at an array. I think of it as a pointer and a block. A block of probably contiguous data in memory — its close together if not physically in hardware then as we may address it from software. And I see the array also as a pointer I can use to reference that block. That points to sections in that block of memory. Where each section is the start & end of a chunk of memory. e.g. the difference between ar[1] and ar[2] is [1] points to the start of the 2nd memory block of the array which is the end of the first. While [2] points to the end of the 2rd but the beginning of the 3rd.

Thus if all memory in an array. Had no padding to note and by incrementing or decrementing the memory address. Our point of reference would advance to the next mark. Sorta. If all addresses were in a fixed range of integers, say 0 – 10. address+1 or address-1 would move our reference to +/- 1 sector of memory. — Even if the physical hardware doesn’t address memory like so, it seems to me by the time we hit software we can run on the machine via an OS / run time it gets this way.

| 0 | 1 | 2 | 3 | 4 |5 | 6 | 7 | 8 | 9 | 10 |

To be honest, I don’t know how arrays are implemented. I expect it to be a simple bunch of blocks of memory close together or just a fat segmented block. Where an address reference’s marked points of it. In such a way that we have an abstraction in the language that,

for ( i = 0; i < MAXCNT; i++ ) {
do_something( ar[i] );
}

works, gets down to assembly code that makes just as much sense but is more complicated. Then down to hardware that knows what to make of machine code. And down to the physical machine to run it and a realm for electrical engineering or some thing.

When I think about functions. I tend to think of it as a block of memory with all the data it needs, like variables in its scope and what not. and a system of pointers that handle calling and returning. Like

ch = fgetc( fp );

I think it would allocate memory (I hear C is stack based?) for the function (fgetc), use a pointer to fetch that address (call the function). Set the pointer or another pointer or some t hing like that to the return value of the function. Run the code their some how work it out so what the called function returns is what ch contains when references in memory. To me a variable is just a name for a value.

foo = 5;

To me says instead of typing 5 every where, I’d like to be human and just talk about foo instead. And let you (computer) fill in the value the name points to. Or some thing like that any way.

And in a similar light that I’d want to use ‘ch’ as a reference to the data returned by fgetc(fp) rather then have to know what the freaking location in memory it has !

Ok, so maybe I’m talking out of my ass or maybe I’m getting smarter as time goes on. Who knows…

My lib

Some thing constructive for the night. Cleaned up a lot of stuff in my utility/portability lib. Including a bool datatype for when stdbool.h is not around. And if it is or its C++ use the local boolean.

Aslo tried to make it slightly more friendly to pre-ansi compilers. Not that I’ve ever used one or seen one.. have heard of a few people meeting up with one though !

Basically I started it out both out of interest and Windows. I’m a tad lazy, I’d rather use an err( int, string ) then fprintf a string to stderr and append errno plus call exit() — A good 2 or 3 lines usually. When I can do it in 1 or 2 depending on the type of message I want displayed on exit(). BSD/GNU extensions have err()/warn() routines.

Windows of course lacks this totally as far as I can find. So since I was interested for a long time in how to create libraries I looked up how and implemented the err()/errx() I used so much in it. As well as most of the routines I’ve created in a few small programs. I don’t expect to use the thing for much more then building my programs on Windows w/o having to do a lot of search and replace. I just love err() 😉

Wow… just like when I’m sleepy I find a comment like this as I read lol

2230:         /*
2231: * If the new process paused because it was
2232: * swapped out, set the stack level to the last call
2233: * to savu(u_ssav). This means that the return
2234: * which is executed immediately after the call to aretu
2235: * actually returns from the last routine which did
2236: * the savu.
2237: *
2238: * You are not expected to understand this.
2239: */
2240: if(rp->p_flag&SSWAP) {
2241: rp->p_flag =& ~SSWAP;
2242: aretu(u.u_ssav);
2243: }

Been toying qith QTRuby and Korundum (QT3/KDE3 bindings for Ruby).

So far I think I rather like it hehe.

Got QTRuby installed fine, Korundums being a bit picky by libtool way. Hope to have a PBI with both in it by next week.

Some likes I need to bookmark in my master-bookmarks-file and want to post on PC-BSD forums.

Terry@Dixie$ rf ~/tmp/notes 5:20
–with-qt-dir=DIR where the root of Qt is installed
–with-qt-includes=DIR where the Qt includes are.
–with-qt-libraries=DIR where the Qt library is installed.
–with-smoke[=qt|kde] Smoke: build Smoke for qt+kde or qt only [default:qt]
–without-gl disable 3D GL modes

configured as:
./configure –prefix=/Programs/QT-KDE-Ruby-Runtime1.0 –with-qt-dir=/usr/X11R6/include –with-qt-includes=/usr/X11R6/include –with-qt-libraries=/usr/X11R6/lib/

http://developer.kde.org/language-bindings/ruby/tutorial/tutorial.html

http://developer.kde.org/language-bindings/ruby/tutorial2/tutorial2.html

http://www.arachnoid.com/ruby/RubyGUIProject/index.html

http://developer.kde.org/language-bindings/ruby/kde3tutorial/index.html

arning: you chose to install this package in /Programs/QT-KDE-Ruby-Runtime1.0,
but KDE was found in /usr/local.
For this to work, you will need to tell KDE about the new prefix, by ensuring
that KDEDIRS contains it, e.g. export KDEDIRS=/Programs/QT-KDE-Ruby-Runtime1.0:/usr/local
Then restart KDE.

http://doc.trolltech.com/3.3/how-to-learn-qt.html

Terry@Dixie$ 5:20

am I to young ?

When I first read this, I figured a call to panic() would likely bring down the system or set it in motion to abort before the frag explodes . Maaaybe I’ve just lived in a world where the Blue Screen Of Death (BSOD, a Microsoft copyright) is prevelent a little to long. The idea that it calls update(“which I have yet to disect”), prints an error message and calls the kernels idle() loop times infinty is neat. Rather then bringing the system to a screeching halt right then and there. At first glance I would’ve expected it to take down the system right bam’n’slam now.

/*
* Panic is called on unresolvable
* fatal errors.
* It syncs, prints "panic: mesg" and
* then loops.
*/
panic(s)
char *s;
{
panicstr = s;
update();
printf("panic: %sn", s);
for(;;)
idle();
}

Of course from the fine book for study. It seems the only way out of a panic() attack is a restart any way, but its not an instant ‘crash, have a nice foo&ing day, rebooting now sucker’ kind of thing. Which interestingly a lot of times my Windows machines have gone down, *cough*. Its kind of been to the BSOD what the expression ‘Do not pass go, do not collect $200’ is to monopoly. It dies, you get an error, but it kills itself before you get to read it. Then tells you it was *probably* a driver issue lol.

Note that the above code snippet is probably under the this license.

It is from UNIX Version 6 as viewed from here. File is /usr/src/sys/kern/prf.c

Of Code and Programs

Hmm, do I regret never having formal education in programming ? Not really no. Although I think it would’ve been cool to of had a teacher.

When it comes to languages and what not, every thing I know I’ve basically learned on my own. With the assistance of the fine World Wide Web of course. For what ever reason, don’t know any more lmao. I started learning C++ one day. Said what the heck, installed an IDE and hit the web.

That was maybe 1.5-2.5 years ago I think..

One thing I do think I’ve missed out on. Is being educated on the things that transcend the languages. For example.. implementing a bubble sort in language foo should be easy enough ! But on the other hand. I’d much rather have a strong understanding of sorting algorithms and how to work out such problems my self. Then be able to implement the same solutions in many tongues. Although there’s arguably no optimal algorithm that can solve any problem hehehe.

I find my self most often thinking in C or Pseudo English when trying to express my thoughts about computer code. I know about linked lists and such. But implementation wise I tend to visualize that sorta stuff in C =/.

I don’t know why but Unix, C, and Vi feel just right. Like an extension of my hands. Now, I’m no solid programmer that’s for sure. But for all of my personal study C is my strongest language. I’m not sure which I’m better at expressing my self in. English or C, its like a First and Second language kinda thing =/.

I don’t really think I’m cut out for systems work but I often think about it. Stuff like implementing languages, compilers, drivers e.t.c. all interest me. Hell I’d write my own device drivers if I knew what the heck I was doing. Only thing is I don’t :@

For me the language is a way of expressing a problem, an idea, or maybe even a solution. Although I reckon its meant to be easier for the computer to understand then humans lol. When reading programs I find the hardest things not figuring out what the code does. But how it interacts with the things around it.

Like, the initiation code in the FreeBSD kernel. The codes right there, plain enough as the nose in front of my face. But its hard to understand it. Because I know jack about it. The intimate relationship between the hardware… hard to grasp that fine. Yet its some thing that interests me so.

alas, tis late and I have a feeling to be close to some code. But I have no problem to solve. Well other then a little idea for the Rct Checklist hehe. I know near diddly squat about PHP and MySQL. But its fun and the syntax is close enough to C/C++/Java/Perl that I can figure it out, looking up a few odds and ends to be sure. As I go along with it. Like functions scope.

I do rather like C in that regard, I feel how it handles scope and linkage to be rather logical. Yet in a simple manor for most of it.

While I’m to tired to understand why this writes past the end of the array

#include <assert.h>
#define bounds(_i, _n) (assert( (unsigned) (_i) < (_n) ), (_i) )
....

/*
* fout is what we are appending to and should be open rw as necessary.
* farray is an array of file pointers, "farsize" is the size of the array.
*/
void
concatenate( FILE *fout, FILE *farray[], const unsigned char *farsize) {

int c;
unsigned int fi = 1;
FILE *fin; /* current segment of farray[] to fout. */

while ( (fi < farsize[0])) {
fin = farray[bounds(fi, *farsize)];
fi++;
while ( (c = fgetc(fin )) != EOF ) {
fputc( c, fout );
}
}
}

I’m GOING TO BED. 0832 Zulu time on my clock…. must sleeep sleep….

what is that again?

Well since Windows lacks fgetln() but as far as I can tell the BSD and GNU C Libraries have it.

/* The origenal, basically the same as one of the functions in FreeBSDs head(1) implementation.

static void
read_top( FILE *fp, int lncnt ) {

char *cp;
size_t error, rlen;
while ( lncnt && (cp = fgetln( fp, &rlen )) != NULL ) {
error = fwrite( cp, sizeof(char), rlen, stdout );
if ( error != rlen )
err( 1, "stdout" );
lncnt--;
}
}

/* A new version of read_top that *should* be a bit more standard compilent and simple to read */

static void
read_top( FILE *fp, int lncnt ) {

int c = 0;
int f = 0;

while ( (c < lncnt) && (f != EOF ) ) {
f = fgetc( fp );
printf( "%c", f );
if ( (f == 'n') ) {
c++;
}
}
}

The biggest problem with rf.c is the use of err()/errx(), a nice pair of Macros that expand to a fairly compatible meaning would be nice for portability. *cough* Windows *cough* and I don’t even want to know how groff works on WIN32 if at all….

10 Thou shalt foreswear, renounce, and abjure the vile heresy which claimeth that “All the world’s a VAX”, and have no commerce with the benighted heathens who cling to this barbarous belief, that the days of thy program may be long even though the days of thy current machine be short.
This particular heresy bids fair to be replaced by “All the world’s a Sun” or “All the world’s a 386” (this latter being a particularly revolting invention of Satan), but the words apply to all such without limitation. Beware, in particular, of the subtle and terrible “All the world’s a 32-bit machine”, which is almost true today but shall cease to be so before thy resume grows too much longer.

Ten Commandments of C Programming

This some times reminds me of how I feel about assumtions. Uusally met with me thinking.

“I’m not running Windows, !@#$ you”

“I’m not running Linux, !@#$ you”

“I’m not using MS-DOS, !@#$ off!”

“I’m not working in Visual BASIC or Visual C++, really un-!@#$ you”

“What if I’m not on a 32-Bit system, oh go !@#$ your self”

lol.

1 Thing I’d love to see. Is a simple yet powerful language like Perl/Python/Ruby thats got a C/C++ style compiler like GCC. Like being able to run the C pre-processor on the files before compilation and being able to link the object files together into an executable.

But also, a simple interpreter that implements the standard library and can run single file ‘scripts’ like a Bourne Shell. Yet with the options of being able to ‘link’ to pre-compiled libraries of code to extend itself in order to run the script. That way, people could use the interpreter for use interactive (like irb / python) yet run scripts and not have to have a development environment (compiler and friends) and any precompiled libraries could be distributed with the script.

Like

import math_module
import sockets_module

Compile the app and link it to a math and socket library. Or i f we’re using the interpreter.

foo -l lib1, lib2

or even in the script

#!/usr/bin/foo -L /usr/lib/foo/

Would be kinda cool.

The power, flexibility, and speed of a compiler yet the simplicity of an interpretor. But with keeping the ability to also use various libraries of code with the scripts. One could probably do some preprocessor work to include the library code in the script before using it too and save disk space.

Wouldn’t it be awesome if one could work on a Project in Python instead of C++ and keep a compiled executable. Yet when ya need a little script for some ‘loose ends’ to just go ahead and write a script to do it in the same language as the project ? Hehehehe.

I think D has the ability of doing a script, like #!/path/compiler -run at the top of the file. No clue if its a dual-purpose compiler/interpretor or if it just compiles an executable in temp space and runs it or what.