[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference hydra::amiga_v1

Title:AMIGA NOTES
Notice:Join us in the *NEW* conference - HYDRA::AMIGA_V2
Moderator:HYDRA::MOORE
Created:Sat Apr 26 1986
Last Modified:Wed Feb 05 1992
Last Successful Update:Fri Jun 06 1997
Number of topics:5378
Total number of notes:38326

1190.0. "Lattice 4.0 bug?" by WJG::GUINEAU (The Mathematics of Reality ?) Wed Feb 24 1988 18:46


Could someone with Lattice 4.0 try to compile this small example
and let me know the results?  I compiled it under Lattice 4.0
on my Amiga and get wierd results (wrong values returned from 
sscanf() )

I compiled exact same test on VAX and everthing worked fine.



#include <stdio.h>

main()
{
int	hrs,mins,secs;
char	*clock;


clock = "17:07:57";

sscanf(clock,"%2D:%2D:%2D",&hrs,&mins,&secs);

printf("clock: %s, hrs: %d, mins: %d, secs: %d\n",clock,hrs,mins,secs);


}

T.RTitleUserPersonal
Name
DateLines
1190.1Help (maybe???)LEODLN::BAHLINThu Feb 25 1988 12:4314
    I'm new to C and also to Lattice so I could be dead wrong but .....
    
    I think you really need to look at 'clock'.  You declared it as
    a pointer then loaded it with a string, not an address.  Try this
    
    char clock[StringLengthYouWant];  /* different declaration */
    
    Then use 'clock' just like you did before in the other statements.
    C will automatically recognize a character array in your parameter
    passings and pass a pointer so you don't need to declare *clock.
    
    If this works on VAX then maybe the bug/inconsistency is really
    in VAX C, or it is a 'smarter' compiler.
    
1190.2It's not the clock, it's the integer sizePRNSYS::LOMICKAJJeff LomickaThu Feb 25 1988 13:3916
No, I don't think anything's wrong with "clock". I've been using C for
years.  The value of a quoted string in C is it's address, and it is
perfectly legitimate to assign a char* to a quoted string in this way.
Note that you have the address of the literal string, and if you change
it, it's changed for good.

I don't have LATTICE-C, but in Mark Williams C for the Atari-ST, the
upper-case "%D" is used to refer to a "long" parameter, not an "int"
parameter.  I suspect that what is happening is that "sscanf" is
altering FOUR bytes of memory in returning the decimal values, rather
than the TWO you have declared by calling it an "int".  Under VAXC,
"int" and "long" are the same thing, as the natural size for integers
is 32 bits.  On the 68000, the natural size for integers is 16 bits.

I would suggest eigher changing the declaration of "hrs,mins,secs" to be
"long", or changing the sscanf string to "%2d:%2d:%2d".
1190.3Still not sure...WJG::GUINEAUThe Mathematics of Reality ?Thu Feb 25 1988 18:0319
>Note that you have the address of the literal string, and if you change

That was just an example. The real "clock" points to the current system
time (at one time anyway...)

> upper-case "%D" is used to refer to a "long" parameter, not an "int"

I remember reading this. I thought I tried both (originally it was "%d:%d:%d"
then I read the manual and tried capital "D". I was getting the numbers
but for some reason it would skip the first in teh source string:"

clock = "15:10:23";
sscanf(clock,"%d:%d:%d",&hrs,&mins,&secs);

returned hrs as 10, mins as 23, and secs as 0???

John
 
                                                                   
1190.4DEBUG for C?WJG::GUINEAUThe Mathematics of Reality ?Fri Feb 26 1988 10:5831

You know, this is *wierd*.

I tried the exact same test program posted, with the %D's changed to %d
and it worked as expected.

Re-reading the Lattice C manual, it says

on the Amiga, an "int" is the same as a "long int" and both are 32 bits. This
is true for 680x0 micros. If you want a 16 bit variable, use "short", and if
you just want the default integer for counters etc, use "int"


Now I'm somewhat confused. If "int" and "long int" are the same, then why
do %d and %D have any difference on an "int"??


Man, I'm sure spoiled by VAXC and DEBUG...

BTW, is there any GOOD symbolic debuggers availiable for Lattice C? Would
the MANX symbolic debugger work?


(and here's the $25,000 question:) do any of these debuggers provide
both C source *and* 68K assembly like VAX DEBUG does...


John (who's not used to scattering printf's all around...)


1190.5ANGORA::SMCAFEESteve McAfeeFri Feb 26 1988 12:2911
    
    re: -1
    
    There was a Usenet posting recently about Manx's new debugger. 
    Maybe someone still has it lying around.  Yes it does seem to supply
    assembly code for each line of C code.  The article also mentioned that
    Manx object files were now compatible with Amiga object files.  This 
    may mean the debugger will work for lattice (unless you have to compile
    without the debug switch to get the compatible files).
    
    - steve
1190.6COOKIE::WECKERA wholly owned subsidiary of DECFri Feb 26 1988 12:5127
re:	.4

Just for grins: Are you ABSOLUTELY shure that your original format string
was:

	"%d:%d:%d"

instead of:

	" %d:%d:%d"

or:

	":%d:%d:%d"

In either of the these two alternate versions the first integer could be
skipped (jumping over "white space"). I say "could" because some C scanf
scanners use the first white space specifier as an anchor while others
use it as an optional specifier.

Also, next time, print out the return value from scanf and see what it tells
you. I'm sure you'll get back a "2" instead of "3"... this is why the "seconds"
value was always a 0 (never written into).

Just some ideas...
dave

1190.7WJG::GUINEAUThe Mathematics of Reality ?Fri Feb 26 1988 17:288

I started trying all sorts of funny games with the source string (like
adding a 00: to the front, to the back...) And then similar games with
the format string. I'll experiment more this weekend and post the results

John

1190.8"int" is what you make itOLIVER::OSBORNEBlade WalkerMon Feb 29 1988 16:3220
>I tried the exact same test program posted, with the %D's changed to %d
>and it worked as expected.

Well, C *is* case-sensitive, so such behavior is not outside the realm
of "normal" C... 

>Re-reading the Lattice C manual, it says
>on the Amiga, an "int" is the same as a "long int" and both are 32 bits. This
>is true for 680x0 micros....

"int" is what the writer of the compiler thinks it is. Sometimes it's 32, 
sometimes it's 16. That's why you don't want to pass it to functions not
written in C. (i.e., "portable code"). The only *guarantee* is that an "int"
is no shorter than a "short" and no longer than a "long". Lattice is just
being arrogant in equating their definition of "int" with the Amiga's bus.
(Manx decided it was 16, so all arguments passed to functions have to be
cast as "long". Lattice is more compatible with Amiga's libraries, anyway...)

John O.

1190.9sizeof (int) & GreenhillsTLE::RMEYERSRandy MeyersMon Feb 29 1988 21:2219
Re: .8

>Lattice is just being arrogant in equating their definition of "int"
>with the Amiga's bus.

Naw.  When I was looking for a C compiler for the Amiga, one of the
requirements I had at the time was that it support 32 bit ints. 
Unfortunately, it is very easy for assumptions about that sizeof int
to creep into programs, and sizeof (int) == sizeof (long) allows
you to port the maximum amount of poorly written software :-).

>Lattice is more compatible with Amiga's libraries, anyway...

I have often wondered: do the Amiga libraries assume 32 bit ints because
Lattice jumped on board with a 32 bit int compiler, or did Commodore
pick that because the Greenhills C compiler has 32 bit ints?  (I
don't know what int sizes are supported by Greenhills.)  (Greenhills,
by the way, is the C compiler Commodore uses to build the Amiga
software.)