Megamax C oddness

C and PASCAL (or any other high-level languages) in here please

Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team

JonB
Captain Atari
Captain Atari
Posts: 303
Joined: Fri Dec 02, 2011 5:01 pm

Megamax C oddness

Postby JonB » Mon Aug 06, 2012 1:30 pm

Hi all

So here is a simple bit of C:

Code: Select all

int main()
{
  unsigned int mask [ ] = { 0x00, 0x01, 0x03, 0x04 };
  return 0;
}


It won't compile in Megamax C (not even in v1.1). Says the initialisation is illegal. Huh? It's standard K&R - am I missing something, or have I encountered (yet) another Megamax C deficiency that I will have to program around?
Last edited by JonB on Mon Aug 06, 2012 2:34 pm, edited 2 times in total.
Too many retro computers here: 1040STfm, Mega4, Ultrasatanx2 , Amiga A500, A500+ and A1200, Acorn Atom x2, BBC Micro, Electron, Spectrum 48k x2, +48, +128k, QL, Oric Atmos, ZX81, Memotech MTX512, Amstrad 6128 x2..

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 799
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Megamax C oddness

Postby mfro » Mon Aug 06, 2012 2:09 pm

JonB wrote:...Says the initialisation is illegal...


... which is entirely correct. What you probably want to do is initialize an array:

Code: Select all

    int main()
    {
      unsigned int mask[] = { 0x00, 0x01, 0x03, 0x04 };
      return 0;
    }


which might still not be exactly what you want. It will produce the following:

0000 0001 0003 0004

while you might expected it to produce something like

0001 0304 0000 0000

which would require to define a char-array.

Regards,
Markus

JonB
Captain Atari
Captain Atari
Posts: 303
Joined: Fri Dec 02, 2011 5:01 pm

Re: Megamax C oddness

Postby JonB » Mon Aug 06, 2012 2:40 pm

Sorry, I realised the error with the [ ] bit - forgot to type it.

When doing this sort of initialisation, it seems that Megamax C will only do it outside of a function, so although the code I originally posted won't compile, this does:

Code: Select all

unsigned int mask[] = { 0x00, 0x01, 0x03, 0x04 };
int main()
{
  return 0;
}



Another error in my original post - the actual program says short int mask [] = (etc) which is a byte array. I had to do this because Megamax doesn't like assigning numbers to chars, it doesn't do implicit typecasts which can be a bit of a double edged sword.

Anyway, am I correct in my conclusion about only being able to do this in global variable space? If so... well, Megamax seems to be a bit crappy. It's a shame it is the C compiler I did all my ST programming with in the old days. Maybe I should switch compilers. I've been playing with Pure C but I'm not particularly convinced.
Too many retro computers here: 1040STfm, Mega4, Ultrasatanx2 , Amiga A500, A500+ and A1200, Acorn Atom x2, BBC Micro, Electron, Spectrum 48k x2, +48, +128k, QL, Oric Atmos, ZX81, Memotech MTX512, Amstrad 6128 x2..

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 799
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Megamax C oddness

Postby mfro » Mon Aug 06, 2012 3:00 pm

JonB wrote:...When doing this sort of initialisation, it seems that Megamax C will only do it outside of a function, so although the code I originally posted won't compile, this does...


Now that you mention it - I think you are right. Megamax indeed couldn't initialize local arrays. It was one of the first (if not the first) ST C-compiler with a usable integrated development environment, however, which made it my personal favorite back then.

It was just too boring constantly changing floppies using the Alcyon C compiler before...

JonB
Captain Atari
Captain Atari
Posts: 303
Joined: Fri Dec 02, 2011 5:01 pm

Re: Megamax C oddness

Postby JonB » Mon Aug 06, 2012 3:52 pm

Oh... how awful. I might have to get another compiler after all!

As to the IDE it came with.. eurgh. I can't get it to work anyway (no instructions) and as I recall it wastes screen space. I used gulam (a unix-like command line interpreter for TOS), Tempus as an editor and nothing else. Since then (20 odd years ago!) I got strong with vi and have a vi clone called elvis on my Mega4. It's slow, but at least I know the hotkeys (almost hardwired into my hands). I would like to acquire a copy of Stevie (the editor elvis was based on, another vi clone but cut down and specifically for the ST).

Thanks for your reply!
Too many retro computers here: 1040STfm, Mega4, Ultrasatanx2 , Amiga A500, A500+ and A1200, Acorn Atom x2, BBC Micro, Electron, Spectrum 48k x2, +48, +128k, QL, Oric Atmos, ZX81, Memotech MTX512, Amstrad 6128 x2..

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12706
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Megamax C oddness

Postby wongck » Mon Aug 06, 2012 11:32 pm

You cannot assume all C compilers does certain thing.
You must look at what version of C standard it conforms to.
Earlier ones may not conform to much standards.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

gothmog
Atari freak
Atari freak
Posts: 53
Joined: Thu Apr 01, 2004 5:23 pm

Re: Megamax C oddness

Postby gothmog » Tue Aug 07, 2012 8:48 am

By any chance, do you have Megamax C version 1.2 ? I've been looking for it for a long time! I only have versions 1.0 and 1.1 ...

JonB
Captain Atari
Captain Atari
Posts: 303
Joined: Fri Dec 02, 2011 5:01 pm

Re: Megamax C oddness

Postby JonB » Tue Aug 07, 2012 10:39 am

I know you are, gothmog, I spotted some of your posts on the subject in my searches. Sadly I haven't got it, just the v1.1 that you're no doubt using right now. I suppose we will have to accept the inevitable and start using a different compiler. I downloaded Pure C for fun, to see if I could get it going with this code (it compiles, so must be more compliant than Megamax). If only I could switch off all the darned warnings and speed it up a little!

@wongck : Megamax C is supposed to be K&R compliant, which means it should support what I am trying to do (I think... been a while since I did any K&R C - it's all ANSI nowadays and C++).. if it only supports a subset of C, should it really be called a C compiler? Moot point now of course..
Too many retro computers here: 1040STfm, Mega4, Ultrasatanx2 , Amiga A500, A500+ and A1200, Acorn Atom x2, BBC Micro, Electron, Spectrum 48k x2, +48, +128k, QL, Oric Atmos, ZX81, Memotech MTX512, Amstrad 6128 x2..

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12706
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Megamax C oddness

Postby wongck » Tue Aug 07, 2012 12:20 pm

well I guess there's always some exceptions to standard... :roll:

Yeah Pure C is great. I guess you would also spotted my postings on Pure C. :wink:
There are some GEM C demo source that came with Pure C, at least on mine.
I think I uploaded them here before.....
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

JonB
Captain Atari
Captain Atari
Posts: 303
Joined: Fri Dec 02, 2011 5:01 pm

Re: Megamax C oddness

Postby JonB » Tue Aug 07, 2012 2:03 pm

In addition, I am battling against 20 years of C++ habits, which tend to die hard.

Example.

Forward declaration of a function has no argument list.

Argument declaration seems odd:

Code: Select all

int myFunc(x, y)
int x;
int y;
{
  /* Do something */
}


Instead of:

Code: Select all

int myFunc(int x, int y)
{
  /* Do something */
}


..but this is my fault for forgetting how it is done in K&R C!
Too many retro computers here: 1040STfm, Mega4, Ultrasatanx2 , Amiga A500, A500+ and A1200, Acorn Atom x2, BBC Micro, Electron, Spectrum 48k x2, +48, +128k, QL, Oric Atmos, ZX81, Memotech MTX512, Amstrad 6128 x2..

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12706
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Megamax C oddness

Postby wongck » Wed Aug 08, 2012 12:05 pm

JonB wrote:In addition, I am battling against 20 years of C++ habits, which tend to die hard.

don't.... try gcc.
But you may need Mint.
What Atari are you using ?
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

Dio
Captain Atari
Captain Atari
Posts: 451
Joined: Thu Feb 28, 2008 3:51 pm

Re: Megamax C oddness

Postby Dio » Wed Aug 08, 2012 1:19 pm

C was extraordinarily unreadable before ANSI C came along. I had three or four goes at getting it in the 80s and just couldn't make it fit in my head until I started working on projects in ANSI format.

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12706
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Megamax C oddness

Postby wongck » Wed Aug 08, 2012 1:31 pm

Pure C was pretty easy to read.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 5089
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Megamax C oddness

Postby simonsunnyboy » Wed Aug 08, 2012 3:31 pm

C is freestyle for its formatting so modern code can look disgraceful aswell.

i personally recommend running code reformatting tools on C sources to fix theri styles to be more legible, whatever that means for the individual. I can recommend the tools astyle (i use that personally) and uncrustify (which we use at the job)

Maybe someone should port them to the Atari?
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12706
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Megamax C oddness

Postby wongck » Thu Aug 09, 2012 1:39 am

simonsunnyboy wrote:C is freestyle for its formatting so modern code can look disgraceful aswell.

yeah, that's true.
When I find some code, I always "change" the layout to my own style, so I can read and understand it better.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

JonB
Captain Atari
Captain Atari
Posts: 303
Joined: Fri Dec 02, 2011 5:01 pm

Re: Megamax C oddness

Postby JonB » Thu Aug 09, 2012 9:07 pm

wongck wrote:
JonB wrote:In addition, I am battling against 20 years of C++ habits, which tend to die hard.

don't.... try gcc.
But you may need Mint.
What Atari are you using ?


Mega ST4. I don't think there is a gcc for it...
Too many retro computers here: 1040STfm, Mega4, Ultrasatanx2 , Amiga A500, A500+ and A1200, Acorn Atom x2, BBC Micro, Electron, Spectrum 48k x2, +48, +128k, QL, Oric Atmos, ZX81, Memotech MTX512, Amstrad 6128 x2..

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12706
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Megamax C oddness

Postby wongck » Thu Aug 09, 2012 11:25 pm

JonB wrote:Mega ST4. I don't think there is a gcc for it...

yes there is.... but a old one. May not do C++. not sure.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
mfro
Atari Super Hero
Atari Super Hero
Posts: 799
Joined: Thu Aug 02, 2012 10:33 am
Location: SW Germany

Re: Megamax C oddness

Postby mfro » Fri Aug 10, 2012 6:15 am

Why don't you give AHCC a try?

It's at least more ANSI-C compatible than the old Megamax. UI is a bit - err - not to everyone's taste - but you can always use the commandline utilities together with QED.

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 5089
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Megamax C oddness

Postby simonsunnyboy » Fri Aug 10, 2012 3:18 pm

mfro wrote:Why don't you give AHCC a try?

It's at least more ANSI-C compatible than the old Megamax. UI is a bit - err - not to everyone's taste - but you can always use the commandline utilities together with QED.


I second that! AHCC is great and esay to use. The UI is tailored for multitasking environments so it does not allow to run the compiled program. But its editor has syntax highlight.

I personally use the TTP compiler via emulation most of the way and edit my sources on the PC from Code::Blocks or gedit.
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

Henk Robbers
AHCC Developer
AHCC Developer
Posts: 39
Joined: Mon Nov 14, 2011 2:37 pm

Re: Megamax C oddness

Postby Henk Robbers » Fri Aug 10, 2012 9:14 pm

FYI:

AHCC and Pure C implement full K&R 2nd edition (ANSI C or C89)

Megamax C is K&R 1st edition.

JonB
Captain Atari
Captain Atari
Posts: 303
Joined: Fri Dec 02, 2011 5:01 pm

Re: Megamax C oddness

Postby JonB » Sat Aug 11, 2012 7:54 am

ahcc - anyone got a link?
Too many retro computers here: 1040STfm, Mega4, Ultrasatanx2 , Amiga A500, A500+ and A1200, Acorn Atom x2, BBC Micro, Electron, Spectrum 48k x2, +48, +128k, QL, Oric Atmos, ZX81, Memotech MTX512, Amstrad 6128 x2..

User avatar
simonsunnyboy
Moderator
Moderator
Posts: 5089
Joined: Wed Oct 23, 2002 4:36 pm
Location: Friedrichshafen, Germany
Contact:

Re: Megamax C oddness

Postby simonsunnyboy » Sat Aug 11, 2012 8:30 am

JonB wrote:ahcc - anyone got a link?


http://members.chello.nl/h.robbers/ or http://ahcc.atari.org/ which points to the former.

Henk does a marvellous job there! :cheers:
Simon Sunnyboy/Paradize - http://paradize.atari.org/

Stay cool, stay Atari!

1x2600jr, 1x1040STFm, 1x1040STE 4MB+TOS2.06+SatanDisk, 1xF030 14MB+FPU+NetUS-Bee

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12706
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Megamax C oddness

Postby wongck » Sat Aug 11, 2012 8:41 am

Should be here.
My Stuff: FB/Falcon CT63 CTPCI ATI RTL8139 USB 512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
charles
10 GOTO 10
10 GOTO 10
Posts: 2476
Joined: Tue Aug 17, 2004 12:11 am
Location: ont. Canada
Contact:

Re: Megamax C oddness

Postby charles » Sat Aug 11, 2012 11:59 pm

i have weird situation ,
found bug in cubase hack....
it seems the sys ex in the mix module once mixeddown ,
trunciates its self like a 'c' string

and not

by finding the status "$F7" EOX byte..

could this be a hack done in megamax 'c',,,????? cardinal word or short int?

ok , just a random thought i thought i'd throw in

charles
The radioactive half-life : )
Atari is a lifestyle,not a hobby.
HOLD ON ! ! ! Im printing unreadable characters ...!


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 2 guests