TIP: Click on subject to list as thread! ANSI
echo: locsysop
to: Roy Mcneill
from: Bob Lawrence
date: 1995-04-25 08:39:04
subject: C

RM> One of the big strengths of the profiler is that it can point
 RM> out sluggish bits of code in places you never thought of
 RM> looking.

  I have never used it, but I'll give it a go. I find it incredible
that Borland have an "integrated" IDE that can't call it directly, so
I gave it the flick.

... [later - is this profiler any good, or what? It makes it too easy.

 RM> The delay involved in switching between the IDE and the
 RM> profiler didn't really bother me. In each subdir, I had a file
 RM> called C.BAT which contained "bc hello.prj" or equivalent.

  I'm not sure what you mean here, Roy. Did you have a different batch
file for every project (like .mak), or did you rewrite the c.bat every
time you started a new project? And why in every subdirectory? Why not
just the working directory?

 RM> If I was using the profiler a lot there would also be TP.BAT,
 RM> "tf386 hello.exe". (I was using BC3v0, some of the prognames
 RM> may be a bit different in 3v1.)

  I'm still not clear how this works. I am in the IDE typing away and
I'd like to find out how long the loop is taking in my project the way
I've written it. What do I do? Shell to DOS and type "TP project.c" 
Or do I close the IDE first?

 RM> What's instr()?

  It's strstr() with a starting point rather than just the beginning,
that also works for characters... and returns an integer rather than a
pointer that has to have the start subtracted.

 RM> One of the good things about C is its wealth of functions.

  ROFL!!! It has the same thing done five different ways each, rather
than just one that does it all... and listed alphabetically but
cleverly using non-alphabetic names so that similar functions are
spread all over the place like a mad woman's shit. I really admire it.
If I wanted to totally root a beginner, this is how I would do it.

 RM> Take a closer look at the strxxx() collection, you'll find a
 RM> few that you'll use a lot (eg strcat, strcpy, strncpy, strcmp,
 RM> strlen), and the rest just stay in the back of the mind.

  I did that some time ago, Roy. I was forced to learn all these
shitty things off by heart, and I *still* missed sprintf() and scanf()
because they were not listed in the "strxxx" group of functions.

  strcat() for instance is one of my favourites. If I have a buffer
and want to add a bit on the end without destroying the original (so I
can use it later)... how? No way in C; shit-easy in VB.

  For instance... what's the difference between strcpy and stpcpy? Can
you remember? I can't, and I've just looked it up.

  With strncpy(), what if you want to copy from a certain place? How
do you set the starting point? Use strchr or strstr, first... or use
pointers and then have to give it space each time?

  Bloody C does everything at least twice; it generates fifty str
functions, and *still* misses the only two that you *really* need.

  With VB, I only have to remember two functions: instr() and mid()...
plus len(). Even strlen() gives me the shits. What is the point of
calling it STRlen? How many len's are there? Does C do a flelen and a
streamlen... no. So why not just LEN()! and save me typing str all the
bloody time!

 RM> Don't try to memorize them all (I never have), just remember
 RM> that "something like that exists, I'll go look it up". In the
 RM> IDE that's just an F1 key away.

  *where* do you look it up? I have been silly enough to look up the
"str" functions under "str". What a shame that
sprintf() is under "sp"
Borland help is a misnomer, they should call it "stuffup".

 RM> Good idea. Thinking of a string as an array of chars will keep
 RM> you aware that it has a certain size, unlike the free-form
 RM> strings in Basic.

  Unfortunately... I wrote that before I realised that the only way to
write fucntions is to pass by value and you need pointers to do that.

 BL> I've just discovered that it hasn't got a mid() function
 BL> either! I don't believe it!

 RM> Huh? To copy out K characters starting at character M (M=0 for 1st
 RM> char) from string Instr to string Outstr, try
 RM> 
 RM> J = strlen(Instr);
 RM> if( (M < J) && ((M+K) <= J))
 RM> {
 RM> strncpy( Outstr, Instr+M, K);  /* direct equivalent of mid() */
 RM> Outstr[J] = '\0';   /* see strncpy() docs for why */
 RM> }
 RM> else
 RM> printf("K and/or M too big...\n");

  Are you kidding, Roy? I don't believe that you expect me to write
all that shit instead of: out$=mid$(in$, start, length) which
automatically takes care of wrong lengths, and that instr is a pointer
and outstr has space allocated. The only way to be sure it will work,
is to make both instr and outstr pointers, and do a  char * malloc(J)
in the middle of the function to get a dynamic allocation of memory.
Either that, or I am *still* confused by pointers.

 RM> Does the same thing, but has full control if things go wrong.
 RM> How does mid() react if the input string is too short?

  It does the best it can... and writes what's there. This is a vast
improvement on copying command.com (or whatever happens to be in
memory at the time) the way that C does it. ROFL!!

 RM> Huh? again... Can Basic do a case insensitive string
 RM> comparison? (see stricmp())

  Of course it can; just toss in a ucase$() or lcase$() first. I must
admit that I haven't done one of those yet, but I've used a hell of a
lot of instr() and mid().

  I'm not proposing BASIC as the ideal language (rofl). I am merely
pointing out that the guy who wrote the C string functions needs a
good kicking. Strings is where C falls apart. There is no way to avoid
using pointers, and what remains is basically a mess. This mess is not
helped by the dopey functions they provide... provided, BTW, in an
effort to hide the problems that C has in passing a string in a
function.

Regards,
Bob
___ Blue Wave/QWK v2.12
@EOT:

---
* Origin: Precision Nonsense, Sydney (3:711/934.12)
SEEN-BY: 711/934
@PATH: 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.