Re: A chip too far? Where is your solution Mr Larkin?



On a sunny day (Wed, 20 Aug 2008 07:53:03 -0700) it happened John Larkin
<jjlarkin@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
<8bboa45fqqqr2kbvbgct271v2uen83rlv0@xxxxxxx>:

All have been blown away by Intel and Microsoft, x86 and Windows and
C, the worst of the litter.

Not to be so in envy,
You can learn C too, it is a beautiful language:

// test.c
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char **argv)
{
#define SMART 10
#define c_programmer SMART
int he;


for(he = 0; he <= SMART; he++)
{
if(he == c_programmer)
{
fprintf(stderr, "\
For he's a jolly good fellow, for he's a jolly good fellow\n\
For he's a jolly good fellow, which nobody can deny\n\
Which nobody can deny, which nobody can deny\n\
For he's a jolly good fellow, which nobody can deny\n");
}
}


exit(1);
} /* end function main */

gcc -o test test.c
grml: ~ # ./test
For he's a jolly good fellow, for he's a jolly good fellow
For he's a jolly good fellow, which nobody can deny
Which nobody can deny, which nobody can deny
For he's a jolly good fellow, which nobody can deny
grml: ~ #

Start reading Kernigan & Ritchie 'The C programming language'.
http://www.amazon.com/C-Programming-Language-2nd-Ed/dp/0131103709
It is a bit old, but they invented it...

In fact C is a step upwards the ladder from your asm.
It has many of the features that asm alows, making C especially suited for writing
drivers.
The pointers are absolutely great for writing high speed code,
with some self dicipline you won't make many mistakes with those.
Always check in a function for null pointers, and do a graceull exit.

I mean like this:

#include <stdlib.h>
#include <stdio.h>


int debug_mode = 1;

#define ERROR 0
#define SUCCESS 1
#define SUCKS 1
#define OK 0

char *text;
int lines;

int my_function(char *text, int *lines)
{
if(debug_mode)
{
fprintf(stderr, "my_program: my_function(): text=%s lines=%p\n", text, lines);
}

if(! text) return ERROR;
if(! lines) return ERROR;

// count text lines

return SUCCESS;
}


int main(int argc, char **argv)
{
#define SMART 10
#define c_programmer SMART
int he;


if(! my_function(text, &lines) )
{
fprintf(stderr, "Coding error.\n");

exit(SUCKS);
}

exit(OK);
} /* end function main */


grml: ~ # gcc -o test test.c
grml: ~ # ./test
my_program: my_function(): text=(null) lines=0x8049820
Coding error.
grml: ~ #

LOL

.