[comp.sys.amiga.programmer] Help this neophyte...

barbecue@pine.circa.ufl.edu (MERCER) (03/05/91)

Assuming this post gets through, I am looking for some help
with my novice attempts to program in C on my Amiga 500.
I am just beginning to learn C, and I am using Aztec C 3.6a.
(Yes, I know I need to upgrade...)
My first question is this: when I attempted to write a simple
program to do some string manipulations, I encountered a bug|
feature|pecadillo of my compiler with regard to the index(),
rindex(), strchr() and strrchr() functions.  It seems that these
functions are returning integers, when the documentation says
they should return char pointers.  I have looked in all my reference
materials, and tried C on other systems, and these functions work
as advertised.  Why is Manx returning these integers?  I even tried
using the integers in several ways, but had little luck.  These are
the kinds of experiences that can really darken one's day when one
is a novice.  I do not NEED these functions, but it would be nice
if they would work.  Can anyone explain this and possibly offer a 
solution?  Please don't suggest upgrading, as when and if I do
upgrade, (which will not be anytime soon due to budgetary constraints) 
I will be thinking about whether to stay with Manx or go Lattice.
This is my second question: given that I will eventually upgrade,
should I stay with Manx or should I switch to Lattice?  I am not
a professional, my programs are mainly simple utilities and amusing
things from Scientific American, and MIDI music generation projects.
Given that I probably won't be getting a 3000 anytime soon, which
compiler is best for me?  How ANSI compliant/compatible are they?
How much do they cost?  And can anyone suggest ftp sites, specific
fish disks, or other specific sources of programming aids and utils
(things like a make program, a lint, a debugger, and in particular,
text files which list or describe bugs, problems, idiosyncrasies, 
and non-portabilities of Manx C?  I am grateful in advance.  
Email repsonses are preferred, cash donations gleefully accepted. 

BARBECUE@pine.circa.ufl.edu - Internet
BARBECUE@UFPINE - BITNET
Barbecue@ribs.grill.patio.backyard - Foodnet

higgin@cbmvax.commodore.com (Paul Higginbottom - CATS) (03/06/91)

In article <27282@uflorida.cis.ufl.EDU> barbecue@pine.circa.ufl.edu writes:
$My first question is this: when I attempted to write a simple
$program to do some string manipulations, I encountered a bug|
$feature|pecadillo of my compiler with regard to the index(),
$rindex(), strchr() and strrchr() functions.  It seems that these
$functions are returning integers, when the documentation says
$they should return char pointers.  I have looked in all my reference
$materials, and tried C on other systems, and these functions work
$as advertised.  Why is Manx returning these integers?  I even tried
$using the integers in several ways, but had little luck.  These are
$the kinds of experiences that can really darken one's day when one
$is a novice.  I do not NEED these functions, but it would be nice
$if they would work.  Can anyone explain this and possibly offer a
$solution?

The answer to your problem is actually very simple.  Those functions
DO work as documented, but the compiler assumes all functions return
ints by default, unless declared otherwise.  Usually, you'd use the
'extern' keywork, e.g.:

my_func()
{
	extern char *index();

	char *x;

	...
	x = index(...);
	...
}

Technically speaking you don't need the 'extern', by the way, but you
must declare the function if it doesn't return an int and its source is
not compiled above the function that needs it in the same pass of the
compiler.

$BARBECUE@pine.circa.ufl.edu - Internet
$BARBECUE@UFPINE - BITNET
$Barbecue@ribs.grill.patio.backyard - Foodnet


	Hope this helps,
	Paul.

markv@kuhub.cc.ukans.edu (03/12/91)

In article <27282@uflorida.cis.ufl.EDU>, barbecue@pine.circa.ufl.edu (MERCER) writes:
> Assuming this post gets through, I am looking for some help
> with my novice attempts to program in C on my Amiga 500.
> I am just beginning to learn C, and I am using Aztec C 3.6a.
> (Yes, I know I need to upgrade...)
> My first question is this: when I attempted to write a simple
> program to do some string manipulations, I encountered a bug|
> feature|pecadillo of my compiler with regard to the index(),
> rindex(), strchr() and strrchr() functions.  It seems that these
> functions are returning integers, when the documentation says
> they should return char pointers.

You are probably calling the functions without declarations.  In C if
a function isn't declared it defaults to returning an int.  With Manx
3.6a try including <funcs.h> or <string.h> (not sure of 3.6 include
scheme).  

You need the declarations like this:

	char	*strrchr();

Which says strrchr() returns a char pointer.  Without this line the
compiler assumes an int.  Actually, if an int is the same size as the
pointer (32 bit ints), then the code will still work despite the
compiler warnings (in the case of the Amiga at least).

>  I have looked in all my reference
> materials, and tried C on other systems, and these functions work
> as advertised.  Why is Manx returning these integers?  I even tried
> using the integers in several ways, but had little luck.

Manx 3.6 defaults to 16 bit ints.  You can use 32 bit ints, which I
would advise, esp. since a lot of PD unix code (older stuff)
indiscriminately uses ints to store and manipulate pointers.  Just use
the correct compiler switches and the 32 bit libraries.

> Given that I probably won't be getting a 3000 anytime soon, which
> compiler is best for me?  How ANSI compliant/compatible are they?
> How much do they cost?  And can anyone suggest ftp sites, specific
> fish disks, or other specific sources of programming aids and utils
> (things like a make program, a lint, a debugger, and in particular,
> text files which list or describe bugs, problems, idiosyncrasies, 
> and non-portabilities of Manx C?

If money is an issue, I would strongly advise trying a PD/Shareware
compiler like DICE (or Gcc if you have LOTS of RAM).  These compilers
are more "modern" than Manx 3.6 and support things like function
prototypes that solve a lot of problems like this.

>  I am grateful in advance.  
> Email repsonses are preferred, cash donations gleefully accepted. 
> 
> BARBECUE@pine.circa.ufl.edu - Internet
> BARBECUE@UFPINE - BITNET
> Barbecue@ribs.grill.patio.backyard - Foodnet
-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mark Gooderum			Only...		\    Good Cheer !!!
Academic Computing Services	       ///	  \___________________________
University of Kansas		     ///  /|         __    _
Bix:	  mgooderum	      \\\  ///  /__| |\/| | | _   /_\  makes it
Bitnet:   MARKV@UKANVAX		\/\/  /    | |  | | |__| /   \ possible...
Internet: markv@kuhub.cc.ukans.edu
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~