Sozobon C's a bit broken isn't it?

General Discussion, STOS.

Moderator: troed

User avatar
stephen_usher
Posts: 5583
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Sozobon C's a bit broken isn't it?

Post by stephen_usher »

I was just writing a quick program to dump the contents of the memory mapped into the cartridge address space and found this wonder, e.g.

Code: Select all

#include <stdio.h>

#define CARTSTART 0xfa0000
#define CARTEND 0xfbffff

main()
{
	unsigned char *addr = CARTSTART;
	unsigned char *endaddr = CARTEND;

	for (; addr < endaddr; addr++)
	{
		printf("0x%02x\t", *addr);
	}
}
This code will fail as the test to see if addr is less than endaddr will fail. (Add to this that if you try to use CARTEND in the test then the compilation fails saying that there's in incorrect : expression.)

If you subtract addr from endaddr then you will get a value that's ffffffff.

If you change the start address to 0xfb0000 then it works. It looks like all tests and arithmetic, even on pointers, is 16 bit only, and unsigned arithmetic seems to be sort of signed. That's rather broken.
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
User avatar
rubber_jonnie
Site Admin
Site Admin
Posts: 10480
Joined: Thu Aug 17, 2017 7:40 pm
Location: Essex
Contact:

Re: Sozobon C's a bit broken isn't it?

Post by rubber_jonnie »

I couldn't get Sozobon to work at all, but Pure C is nice. Might see if it works on that.
Collector of many retro things!
800XL and 65XE both with Ultimate1MB,VBXL/XE & PokeyMax, SIDE3, SDrive Max, 2x 1010 cassette, 2x 1050 one with Happy mod, 3x 2600 Jr, 7800 and Lynx II
Approx 20 STs, including a 520 STM, 520 STFMs, 3x Mega ST, MSTE & 2x 32 Mhz boosted STEs
Plus the rest, totalling around 50 machines including a QL, 3x BBC Model B, Electron, Spectrums, ZX81 etc...
czietz
Posts: 548
Joined: Sun Jan 14, 2018 1:02 pm

Re: Sozobon C's a bit broken isn't it?

Post by czietz »

I wonder if it wants the constants to be explicitly defined as long int, i.e. 0xfa0000L, 0xfbffffL. However, why bother with ancient Sozobon C, at all?
User avatar
stephen_usher
Posts: 5583
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Sozobon C's a bit broken isn't it?

Post by stephen_usher »

czietz wrote: Sun Jan 24, 2021 5:23 pm I wonder if it wants the constants to be explicitly defined as long int, i.e. 0xfa0000L, 0xfbffffL. However, why bother with ancient Sozobon C, at all?
When you don't want to boot into MiNT but do want a command line environment for a quick fix thing. Pure C is far too GUI for me. :D

So, it's Gulam + Sozobon C for quick hacks.

P.S. The values put into the pointer variables are correct, so adding an 'L' to the end wouldn't make a difference. It's the pointer arithmetic which is broken.
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
czietz
Posts: 548
Joined: Sun Jan 14, 2018 1:02 pm

Re: Sozobon C's a bit broken isn't it?

Post by czietz »

Hm, apparently you're using a different version of Sozobon C than the one available on Compiler Explorer: https://tinyurl.com/y2w86b45
With that one, your code would not even compile without the cast to "unsigned char *", but then the pointer arithmetic is correct.

PS: You're aware that Pure C has a command-line compiler, too?
User avatar
stephen_usher
Posts: 5583
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Sozobon C's a bit broken isn't it?

Post by stephen_usher »

czietz wrote: Sun Jan 24, 2021 5:41 pm Hm, apparently you're using a different version of Sozobon C than the one available on Compiler Explorer: https://tinyurl.com/y2w86b45
With that one, your code would not even compile without the cast to "unsigned char *", but then the pointer arithmetic is correct.

PS: You're aware that Pure C has a command-line compiler, too?
The version of Sozobon C I'm using was downloaded from umich.edu in about 1990/91... It's a bit old. :-)

Oh, actually, must have been '89 as I was doing my MSc Comp Sci at the time.
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
User avatar
rubber_jonnie
Site Admin
Site Admin
Posts: 10480
Joined: Thu Aug 17, 2017 7:40 pm
Location: Essex
Contact:

Re: Sozobon C's a bit broken isn't it?

Post by rubber_jonnie »

I just tried it on Pure C (I get you don't like GUIs) and had to add L to the values assigned to CARTSTART/CARTEND to have it stop moaning to me about "Constant is long in function main".

It's now moaning about "Non-portable pointer assignment in function main" and "Function should return a value in function main".

Will see if I can fix but I am a C beginner!!

Nice to have a little project to make me think.
Collector of many retro things!
800XL and 65XE both with Ultimate1MB,VBXL/XE & PokeyMax, SIDE3, SDrive Max, 2x 1010 cassette, 2x 1050 one with Happy mod, 3x 2600 Jr, 7800 and Lynx II
Approx 20 STs, including a 520 STM, 520 STFMs, 3x Mega ST, MSTE & 2x 32 Mhz boosted STEs
Plus the rest, totalling around 50 machines including a QL, 3x BBC Model B, Electron, Spectrums, ZX81 etc...
User avatar
stephen_usher
Posts: 5583
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Sozobon C's a bit broken isn't it?

Post by stephen_usher »

Yeah, there should be casts for the address assignments. The warning about main returning a value is a newfangled ANSI C thing. If you make have "void main()" or just have "return 1;" at the end that'll get rid of the annoyance.
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
User avatar
rubber_jonnie
Site Admin
Site Admin
Posts: 10480
Joined: Thu Aug 17, 2017 7:40 pm
Location: Essex
Contact:

Re: Sozobon C's a bit broken isn't it?

Post by rubber_jonnie »

stephen_usher wrote: Sun Jan 24, 2021 6:10 pm Yeah, there should be casts for the address assignments. The warning about main returning a value is a newfangled ANSI C thing. If you make have "void main()" or just have "return 1;" at the end that'll get rid of the annoyance.
Yep, I added void main() and that cleared that up, but still get the "Non-portable pointer assignment in function main" errors for lines 8/9.

It was nice to have something interesting that I could take as a learning point drop in my lap :)
Collector of many retro things!
800XL and 65XE both with Ultimate1MB,VBXL/XE & PokeyMax, SIDE3, SDrive Max, 2x 1010 cassette, 2x 1050 one with Happy mod, 3x 2600 Jr, 7800 and Lynx II
Approx 20 STs, including a 520 STM, 520 STFMs, 3x Mega ST, MSTE & 2x 32 Mhz boosted STEs
Plus the rest, totalling around 50 machines including a QL, 3x BBC Model B, Electron, Spectrums, ZX81 etc...
User avatar
stephen_usher
Posts: 5583
Joined: Mon Nov 13, 2017 7:19 pm
Location: Oxford, UK.
Contact:

Re: Sozobon C's a bit broken isn't it?

Post by stephen_usher »

Yes, lines 8 & 9 should be:

Code: Select all

	unsigned char *addr = (unsigned char *) CARTSTART;
	unsigned char *endaddr = (unsigned char *) CARTEND;
Intro retro computers since before they were retro...
ZX81->Spectrum->Memotech MTX->Sinclair QL->520STM->BBC Micro->TT030->PCs & Sun Workstations.
Added code to the MiNT kernel (still there the last time I checked) + put together MiNTOS.
Collection now with added Macs, Amigas, Suns and Acorns.
Post Reply

Return to “SOFTWARE”