Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
SWIs and BASIC file reading/writing in C++
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 27 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Gazza  
View profile   Translate to Translated (View Original)
 More options 18 Oct, 21:31
Newsgroups: comp.sys.acorn.programmer
From: Gazza <use...@garethlock.com>
Date: Sun, 18 Oct 2009 13:31:21 -0700 (PDT)
Local: Sun 18 Oct 2009 21:31
Subject: SWIs and BASIC file reading/writing in C++
OK... I'm planning to port my Space Invaders clone to C++... On the
whole, the job should be fairly easy, as I've dealt with languages
like JavaScript in the past, which are similar to C/C++ in many
respects. The two aspects I'm not sure about are calling SWIs and file
I/O using C++ routines compatible with BASICs PRINT#/INPUT#, which are
how all my data files are written. Can anybody sort this out for me?

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Johnson  
View profile   Translate to Translated (View Original)
 More options 18 Oct, 23:07
Newsgroups: comp.sys.acorn.programmer
From: Chris Johnson <chrisjohnson+n...@spamcop.net>
Date: Sun, 18 Oct 2009 23:07:26 +0100
Local: Sun 18 Oct 2009 23:07
Subject: Re: SWIs and BASIC file reading/writing in C++
In article
<75fc176e-3ddf-465c-b2ac-a24b888c4...@r5g2000yqb.googlegroups.com>,
   Gazza <use...@garethlock.com> wrote:

> OK... I'm planning to port my Space Invaders clone to C++... On the
> whole, the job should be fairly easy, as I've dealt with languages
> like JavaScript in the past, which are similar to C/C++ in many
> respects. The two aspects I'm not sure about are calling SWIs and file
> I/O using C++ routines compatible with BASICs PRINT#/INPUT#, which are
> how all my data files are written. Can anybody sort this out for me?

For SWI handling I would suggest oslib. A very easy SWI veneer to use.

For file input/output the stdio lib has it all. For example:
fgetc and fputc gets/puts a char from/to a file.
fgets and fputs similar for an array of chars (string)
Then there are fread/fwrite to read/write an array of members (may be
any bytes), and fprintf to write formatted output to a file. stdio
lib also has things such as fopen, fclose. All these are fairly easy
to relate to BASIC file handling commands.

You need to read up a bit on the facilities of the C standard
libraries.

--
Chris Johnson


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gazza  
View profile   Translate to Translated (View Original)
 More options 18 Oct, 23:22
Newsgroups: comp.sys.acorn.programmer
From: Gazza <use...@garethlock.com>
Date: Sun, 18 Oct 2009 15:22:02 -0700 (PDT)
Local: Sun 18 Oct 2009 23:22
Subject: Re: SWIs and BASIC file reading/writing in C++
On Oct 18, 11:07 pm, Chris Johnson <chrisjohnson+n...@spamcop.net>
wrote:

I understand the command side of things, but I need to be able to
convert files written with BASICs PRINT# command. That is why I need
either customised routines to do it, or how BASIC does it, so I can
sort it out!

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Kendrick  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 00:24
Newsgroups: comp.sys.acorn.programmer
From: Rob Kendrick <n...@rjek.com>
Date: Mon, 19 Oct 2009 00:24:16 +0100
Local: Mon 19 Oct 2009 00:24
Subject: Re: SWIs and BASIC file reading/writing in C++
On Sun, 18 Oct 2009 13:31:21 -0700 (PDT)

Gazza <use...@garethlock.com> wrote:
> OK... I'm planning to port my Space Invaders clone to C++... On the
> whole, the job should be fairly easy, as I've dealt with languages
> like JavaScript in the past, which are similar to C/C++ in many
> respects. The two aspects I'm not sure about are calling SWIs and file
> I/O using C++ routines compatible with BASICs PRINT#/INPUT#, which are
> how all my data files are written. Can anybody sort this out for me?

If you're new to C and C++, I would strongly recommend getting to grips
with C before C++; C++ is way more complex, and I think I can count on
the fingers of one hand the number of people I actually trust to write
it.  (And one of them is not me.)

B.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Johnson  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 11:08
Newsgroups: comp.sys.acorn.programmer
From: Chris Johnson <chrisjohnson+n...@spamcop.net>
Date: Mon, 19 Oct 2009 11:08:49 +0100
Local: Mon 19 Oct 2009 11:08
Subject: Re: SWIs and BASIC file reading/writing in C++
In article
<9eff70f6-fc99-4e45-a9f8-5ab1e7b6b...@k19g2000yqc.googlegroups.com>,
   Gazza <use...@garethlock.com> wrote:

I repeat - You need to read up a bit on the facilities of the C
standard libraries. Amplifying a little, and not writting real code
you have for example in BASIC the OPENIN, OPENUP and OPENOUT
commands. These are mirrored by the C function *fopen(filename,
mode). BASICs CLOSE#C% is mirrored by fclose(stream).

PRINT#C%,whatever is mirrored by the far more powerful
fprintf(*stream, "formatstring", parameter list)
where *stream is the eqivalent of file handle
format stream describes what is to be output, e.g. "Value of x is %d
and y is %d\n"
and parameter list is the variables, whose values are to be inserted
in order into the formatstring. %d means 'output a signed decimal'.
You also have e.g. %x for hexadecimal, %f for a double and so on. You
can specify whether in exp or mmm.nnn format and the number of dec
places etc. %s would be a literal string.

Here are some random lines of code :

outfile = fopen ( filename, "w" ) ; /* create new file for write or
reset existing file to zero length */

fprintf ( outfile, "# %s file written by %s\n", pd->file_id, APPNAM )
;

fprintf ( outfile, "MinPadBytes:%d\n", app.v2.min_padding );
fprintf ( outfile, "MaxPadBytes:%d\n", app.v2.max_padding );
fprintf ( outfile, "PadRatio:%d\n", app.v2.padding_ratio );

fprint ( outfile, "This is a simple string, followed by a newline\n")

fprintf ( outfile, "%d,%d\n", int1, int2 ); /* comma separated
variables */

fclose ( outfile ) ;
osfile_set_type ( filename, osfile_TYPE_TEXT ) ; /* from oslib */

That's not so different to the BASIC equivalent is it?

This would result in a test file containing e.g.

# Choices file written by ID3TagEd
MinPadBytes:256
MaxPadBytes:2048
PadRatio:25
This is a simple string, followed by a newline
77,44

--
Chris Johnson


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steffen Huber  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 12:10
Newsgroups: comp.sys.acorn.programmer
From: Steffen Huber <s...@huber-net.de>
Date: Mon, 19 Oct 2009 13:10:31 +0200
Local: Mon 19 Oct 2009 12:10
Subject: Re: SWIs and BASIC file reading/writing in C++

Rob Kendrick wrote:
> On Sun, 18 Oct 2009 13:31:21 -0700 (PDT)
> Gazza <use...@garethlock.com> wrote:

>> OK... I'm planning to port my Space Invaders clone to C++... On the
>> whole, the job should be fairly easy, as I've dealt with languages
>> like JavaScript in the past, which are similar to C/C++ in many
>> respects. The two aspects I'm not sure about are calling SWIs and file
>> I/O using C++ routines compatible with BASICs PRINT#/INPUT#, which are
>> how all my data files are written. Can anybody sort this out for me?

> If you're new to C and C++, I would strongly recommend getting to grips
> with C before C++;

It really depends. People who come from an imperative background often
have problems understanding object-oriented programming, especially if
the imperative language they know have no support for proper ADTs.

> C++ is way more complex, and I think I can count on
> the fingers of one hand the number of people I actually trust to write
> it.  (And one of them is not me.)

The key to learn C++ is to not try and understand the complete
language. Noone fully understands C++. The finer details of the
template mechanism are extremely difficult (and to decide whether
an error you encounter is because the compiler does not work
properly or you have made a mistake is often impossible) to
understand. The precise rules for constructor/destructor
hierarchies are also not really intuitive.

There is a very good introduction to C++ in one of the Qt books
which basically describes only a simple subset of C++ which
is easy to understand and easy to maintain.

At the end of the day, I would always recommend Ada 2005 or
Java or C# with a good introductory book for people who want to
learn programming. For RISC OS of course, all three languages
are a no-go area...

Steffen

--
Steffen Huber
hubersn Software - http://www.hubersn-software.com/


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Kendrick  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 12:23
Newsgroups: comp.sys.acorn.programmer
From: Rob Kendrick <n...@rjek.com>
Date: Mon, 19 Oct 2009 12:23:19 +0100
Local: Mon 19 Oct 2009 12:23
Subject: Re: SWIs and BASIC file reading/writing in C++
On Mon, 19 Oct 2009 13:10:31 +0200

Steffen Huber <s...@huber-net.de> wrote:
> > If you're new to C and C++, I would strongly recommend getting to
> > grips with C before C++;  

> It really depends. People who come from an imperative background often
> have problems understanding object-oriented programming, especially if
> the imperative language they know have no support for proper ADTs.

However, there is plenty in C++ that you must understand that you must
also understand in C, and C is an order of magnitude simpler.

> > C++ is way more complex, and I think I can count on
> > the fingers of one hand the number of people I actually trust to
> > write it.  (And one of them is not me.)  

> The key to learn C++ is to not try and understand the complete
> language. Noone fully understands C++. The finer details of the
> template mechanism are extremely difficult (and to decide whether
> an error you encounter is because the compiler does not work
> properly or you have made a mistake is often impossible) to
> understand. The precise rules for constructor/destructor
> hierarchies are also not really intuitive.

The problem is that it's almost impossible to avoid bizarre, complex
and difficult problems.  Most people don't even realise they've stepped
on a bomb.

> At the end of the day, I would always recommend Ada 2005 or
> Java or C# with a good introductory book for people who want to
> learn programming. For RISC OS of course, all three languages
> are a no-go area...

Vala could be possible, Jan-Jaap van der Geer tweeted this recently;

"Playing around with a little Vala programming under RISC OS wimp using
OSLib bindings and it just works! Sooo nice! OO without C++ ugliness!"

B.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Theo Markettos  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 13:22
Newsgroups: comp.sys.acorn.programmer
From: Theo Markettos <theom+n...@chiark.greenend.org.uk>
Date: 19 Oct 2009 13:22:12 +0100 (BST)
Local: Mon 19 Oct 2009 13:22
Subject: Re: SWIs and BASIC file reading/writing in C++

Chris Johnson <chrisjohnson+n...@spamcop.net> wrote:
> I repeat - You need to read up a bit on the facilities of the C
> standard libraries. Amplifying a little, and not writting real code
> you have for example in BASIC the OPENIN, OPENUP and OPENOUT
> commands. These are mirrored by the C function *fopen(filename,
> mode). BASICs CLOSE#C% is mirrored by fclose(stream).

Indeed, but the OP is trying to read files written by PRINT# etc.  These are
written in a peculiar way (eg strings are backwards) due to memory
constraints on the BBC Micro.  I'm not aware of a C library to read files
written by PRINT#

Gareth, I think the BASIC file formats are documented in the BBC BASIC
manual. If you don't have the RISC OS one, I'm sure one of the BBC Micro
manuals would suffice and you can find them on the net - the formats have
barely changed since the BBC.

Then you just need to write a bit of code to read the files in one byte at a
time and interpret the contents.  If you just want strings and integers it
shouldn't be too complex.  Use fgetc() to read in a character and fill in
the result variables as you go (writing more efficient code can be left for
later).  If it helps, write this bit in BASIC first (using just, OPENIN,
CLOSE# and BGET#) and then convert it to C.

Theo


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ste (news)  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 13:26
Newsgroups: comp.sys.acorn.programmer
From: "Ste (news)" <st...@revi11.plus.com>
Date: Mon, 19 Oct 2009 13:26:11 +0100
Local: Mon 19 Oct 2009 13:26
Subject: Re: SWIs and BASIC file reading/writing in C++
In article <50aca05762chrisjohnson+n...@spamcop.net>,
   Chris Johnson <chrisjohnson+n...@spamcop.net> wrote:

> That's not so different to the BASIC equivalent is it?

Don't forget BASIC's PRINT# outputs the bytes of the string in reverse
order, annoyingly. Likewise, INPUT# reads them in reverse order.

Ta,

Steve

--
Steve Revill @ Home
Note: All opinions expressed herein are my own.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chris Johnson  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 14:52
Newsgroups: comp.sys.acorn.programmer
From: Chris Johnson <chrisjohnson+n...@spamcop.net>
Date: Mon, 19 Oct 2009 14:52:15 +0100
Local: Mon 19 Oct 2009 14:52
Subject: Re: SWIs and BASIC file reading/writing in C++
In article <50acacead4st...@revi11.plus.com>,
   Ste (news) <st...@revi11.plus.com> wrote:

> In article <50aca05762chrisjohnson+n...@spamcop.net>,
>    Chris Johnson <chrisjohnson+n...@spamcop.net> wrote:
> > That's not so different to the BASIC equivalent is it?
> Don't forget BASIC's PRINT# outputs the bytes of the string in
> reverse order, annoyingly. Likewise, INPUT# reads them in reverse
> order.

Sorry - didn't click that OP was wanting to read from pre-existing
files. Notwithstanding that, as I said before the c function fgetc ()
will read a char from a file. Thus it is simple enough to read the
chars into a buffer and then reverse them. Similarly fputc() to write
the file.

Why not forget about BASIC PRINT#, and rewrite the new prog in C
using the standard functions. If there are existing files that must
be used by the new prog, why not write a simple utility to convert
the files once and for all over to the new format.

Must confess, I rarely used BASICs PRINT#, preferring
BPUT#handle%,string$ which is more akin to the C functions fprintf
etc.

--
Chris Johnson


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Theo Markettos  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 16:47
Newsgroups: comp.sys.acorn.programmer
From: Theo Markettos <theom+n...@chiark.greenend.org.uk>
Date: 19 Oct 2009 16:47:31 +0100 (BST)
Local: Mon 19 Oct 2009 16:47
Subject: Re: SWIs and BASIC file reading/writing in C++

Chris Johnson <chrisjohnson+n...@spamcop.net> wrote:
> Why not forget about BASIC PRINT#, and rewrite the new prog in C
> using the standard functions. If there are existing files that must
> be used by the new prog, why not write a simple utility to convert
> the files once and for all over to the new format.

Good idea.  The converter can even be written in BASIC :)

Theo


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Amin Kharchi  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 21:47
Newsgroups: comp.sys.acorn.programmer
From: Amin Kharchi <amin....@kharchi.eu>
Date: Mon, 19 Oct 2009 22:47:57 +0200
Local: Mon 19 Oct 2009 21:47
Subject: Re: SWIs and BASIC file reading/writing in C++
Rob Kendrick schrieb:

> If you're new to C and C++, I would strongly recommend getting to grips
> with C before C++; C++ is way more complex, and I think I can count on
> the fingers of one hand the number of people I actually trust to write
> it.  (And one of them is not me.)

It's not a good idea to start with C if you want do C++. [1] C and C++
are different languages. There is no C/C++! [2] There is only C and C++.

Why should I need to no C? If I learn C++ I learn what I need for C++.
No more no less. And of course C++ is different thinking than C. Thats
why C++ was invented.

If I want read a file in C++ I don't need the C library functions. I
just use the C++ library:

---snip---
string str;
ifstream f("test.txt"); // open file for input
f >> str;      // read first word from file to string object
cout << str;   // write string to console
---snip---

What is complex on this example? It looks only complex to someone who
_don't_ know C++. But this is same case for C, Ada, Java, BASIC etc.

If you learn C and then C++ you have wasted time to one language while
you wanted C++.

[1] http://www.research.att.com/~bs/bs_faq.html#prerequisite
[2] http://www.research.att.com/~bs/bs_faq.html#C-slash


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Kendrick  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 21:53
Newsgroups: comp.sys.acorn.programmer
From: Rob Kendrick <n...@rjek.com>
Date: Mon, 19 Oct 2009 21:53:17 +0100
Local: Mon 19 Oct 2009 21:53
Subject: Re: SWIs and BASIC file reading/writing in C++
On Mon, 19 Oct 2009 22:47:57 +0200

Amin Kharchi <amin....@kharchi.eu> wrote:
> If you learn C and then C++ you have wasted time to one language while
> you wanted C++.

Inversely, you get to learn all the shared syntax, pointer arithmetic,
compiling and linking command line syntax, debugging methods, and bags
of other things without being confused by all the ill-thought-out OO
and confusing syntax.

Once you've got to grips with that, the additional syntax introduced by
C++ essentially just bolts on.  Sounds like a win to me.

You don't teach piano by dumping your student in front of a Grand and
give him Mozart to play.

B.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dave Higton  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 22:22
Newsgroups: comp.sys.acorn.programmer
From: Dave Higton <davehig...@dsl.pipex.com>
Date: Mon, 19 Oct 2009 22:22:08 +0100
Local: Mon 19 Oct 2009 22:22
Subject: Re: SWIs and BASIC file reading/writing in C++
In message <hbija0$4i...@news.albasani.net>
          Amin Kharchi <amin....@kharchi.eu> wrote:

> ---snip---
> string str;
> ifstream f("test.txt"); // open file for input
> f >> str;      // read first word from file to string object
> cout << str;   // write string to console
> ---snip---

> What is complex on this example?

The input assignment is left to right, whereas the output assignment
is right to left.

C and C++ have all assignments right to left.  I still fail to
understand why the input assignment was made different.

Dave


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Kendrick  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 22:36
Newsgroups: comp.sys.acorn.programmer
From: Rob Kendrick <n...@rjek.com>
Date: Mon, 19 Oct 2009 22:36:44 +0100
Local: Mon 19 Oct 2009 22:36
Subject: Re: SWIs and BASIC file reading/writing in C++
On Mon, 19 Oct 2009 22:22:08 +0100

Dave Higton <davehig...@dsl.pipex.com> wrote:
> C and C++ have all assignments right to left.  I still fail to
> understand why the input assignment was made different.

A question that has plagued programmers for years.  The best anybody's
ever come up with was that the standard library was devised by the
clinically insane who cut their cocaine with washing powder.

B.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Peacock  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 23:28
Newsgroups: comp.sys.acorn.programmer
From: James Peacock <j.peacock.n...@googlemail.com>
Date: Mon, 19 Oct 2009 23:28:09 +0100
Local: Mon 19 Oct 2009 23:28
Subject: Re: SWIs and BASIC file reading/writing in C++

Amin Kharchi wrote:
> If I want read a file in C++ I don't need the C library functions. I
> just use the C++ library:

> ---snip---
> string str;
> ifstream f("test.txt"); // open file for input
> f >> str;      // read first word from file to string object
> cout << str;   // write string to console
> ---snip---

> What is complex on this example? It looks only complex to someone who
> _don't_ know C++.

It's a bit too simple as errors will be ignored (streams don't throw
exceptions by default, you need to set the exception mask).

In all honesty, streams are not a simple part of C++, though they are
safer than using printf and friends.

James


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
James Peacock  
View profile   Translate to Translated (View Original)
 More options 19 Oct, 23:20
Newsgroups: comp.sys.acorn.programmer
From: James Peacock <j.peacock.n...@googlemail.com>
Date: Mon, 19 Oct 2009 23:20:46 +0100
Local: Mon 19 Oct 2009 23:20
Subject: Re: SWIs and BASIC file reading/writing in C++

Rob Kendrick wrote:
> On Mon, 19 Oct 2009 22:47:57 +0200
> Amin Kharchi <amin....@kharchi.eu> wrote:

>> If you learn C and then C++ you have wasted time to one language while
>> you wanted C++.

> Inversely, you get to learn all the shared syntax, pointer arithmetic,
> compiling and linking command line syntax, debugging methods, and bags
> of other things without being confused by all the ill-thought-out OO
> and confusing syntax.

To be fair, the basic syntax, compiling, linking, debugging are very
similar. The fact that C is /so/ dependent on pointer arithmetic is
arguably a weakness as it is error prone. C++ /can/ reduce dependence
on such things.

> Once you've got to grips with that, the additional syntax introduced by
> C++ essentially just bolts on.  Sounds like a win to me.

I don't think 'just bolts on' would be the correct attitude to take.
To get the best from C++, you need to learn it as a new language and
get out of the low level C mindset.

> You don't teach piano by dumping your student in front of a Grand and
> give him Mozart to play.

Even basic string manipulation is a pain in C, something as simple as
concatenating two strings. Even BASIC can do it better for short
strings. C++ at least offers you the fairly safe and easy to use
std::string, which I think most C++ programmers would consider simple
enough for a beginner to use. I can't say the same about C, it will at
the least involve malloc, possibly free somewhere, memcpy or similar;
and that doesn't even mention the explicit error handling or pointer
ownership details.

C++ is messy, ugly, difficult and complex; but it offers many
advantages over C if used with a bit of thought. You shouldn't and
don't need to dive in at the deep end.

James


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gazza  
View profile   Translate to Translated (View Original)
 More options 20 Oct, 01:14
Newsgroups: comp.sys.acorn.programmer
From: Gazza <use...@garethlock.com>
Date: Mon, 19 Oct 2009 17:14:02 -0700 (PDT)
Local: Tues 20 Oct 2009 01:14
Subject: Re: SWIs and BASIC file reading/writing in C++
On Oct 19, 1:22 pm, Theo Markettos <theom+n...@chiark.greenend.org.uk>
wrote:

Thanks Theo... That was indeed what I was trying to get at. YES. I
used PRINT# on purpose, because it just adds another layer of
obfuscation into the datafiles. That and the dynamic XOR code I'm
using, seems to have made the HiScore table un-breakable so far. I've
had a couple of people I know have a go at it and they couldn't work
out what was going on without viewing the source code first.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Gazza  
View profile   Translate to Translated (View Original)
 More options 20 Oct, 01:23
Newsgroups: comp.sys.acorn.programmer
From: Gazza <use...@garethlock.com>
Date: Mon, 19 Oct 2009 17:23:22 -0700 (PDT)
Local: Tues 20 Oct 2009 01:23
Subject: Re: SWIs and BASIC file reading/writing in C++
Another thing regards the C vs C++ debate, I could probably downgrade
to plain C if struct definitions could inherit other struct
definitions eg...

struct point;
{
int xpos;
int ypos;

}

struct gameObject : point;
{
int xsize;
int ysize;

}

So... Something of type gameObject would have xpos,ypos, xsize & ysize
defined.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John-Mark Bell  
View profile   Translate to Translated (View Original)
 More options 20 Oct, 06:27
Newsgroups: comp.sys.acorn.programmer
From: John-Mark Bell <j...@netsurf-browser.org>
Date: Tue, 20 Oct 2009 06:27:55 +0100
Local: Tues 20 Oct 2009 06:27
Subject: Re: SWIs and BASIC file reading/writing in C++

Struct aggregation is your friend:

struct gameObject {
        struct point base;
        int xsize;
        int ysize;

};

John.

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Steffen Huber  
View profile   Translate to Translated (View Original)
 More options 20 Oct, 13:28
Newsgroups: comp.sys.acorn.programmer
From: Steffen Huber <s...@huber-net.de>
Date: Tue, 20 Oct 2009 14:28:02 +0200
Local: Tues 20 Oct 2009 13:28
Subject: Re: SWIs and BASIC file reading/writing in C++

Rob Kendrick wrote:
> On Mon, 19 Oct 2009 13:10:31 +0200
> Steffen Huber <s...@huber-net.de> wrote:

>>> If you're new to C and C++, I would strongly recommend getting to
>>> grips with C before C++;  
>> It really depends. People who come from an imperative background often
>> have problems understanding object-oriented programming, especially if
>> the imperative language they know have no support for proper ADTs.

> However, there is plenty in C++ that you must understand that you must
> also understand in C, and C is an order of magnitude simpler.

Apart from the basic flow stuff (if/switch, loops) and the curly
braces, I can't think of much that you must know from C that you need
in modern C++. If you use the STL and the standard lib, you don't need
the pointer stuff and malloc and things. You don't need structs and
unions. You don't need the preprocessor apart from import. You don't
need the complicated C string stuff.

In short, everything that is difficult in C (and I talk here from
a solution perspective, not from an implementation perspective -
if you follow that line of argument, you should learn Assembler first,
because it is and order of magnitude simpler than C) you do not need
to know in C++.

Of course, once you encounter mixed language environments, maybe
you want to use C libs from C++, you encounter real-world C++
code that still uses the language like it existed in 1999 - then
you will need to know C.

If you stay within the bounds of "safe C++", I would say
that C++ is actually simpler than C. Let's face it, for real
world problems, C is a very complicated language, because you
have to implement everything in a low-level manner with very
little abstraction and safety to keep you out of trouble.

I would even argue that every language that does not have
a garbage collector by default is a bad language for beginners.

>>> C++ is way more complex, and I think I can count on
>>> the fingers of one hand the number of people I actually trust to
>>> write it.  (And one of them is not me.)  
>> The key to learn C++ is to not try and understand the complete
>> language. Noone fully understands C++. The finer details of the
>> template mechanism are extremely difficult (and to decide whether
>> an error you encounter is because the compiler does not work
>> properly or you have made a mistake is often impossible) to
>> understand. The precise rules for constructor/destructor
>> hierarchies are also not really intuitive.

> The problem is that it's almost impossible to avoid bizarre, complex
> and difficult problems.  Most people don't even realise they've stepped
> on a bomb.

Oh, it is easily possible. There are very few things in C++ that
look easy but are hard to understand.

>> At the end of the day, I would always recommend Ada 2005 or
>> Java or C# with a good introductory book for people who want to
>> learn programming. For RISC OS of course, all three languages
>> are a no-go area...

> Vala could be possible, Jan-Jaap van der Geer tweeted this recently;

> "Playing around with a little Vala programming under RISC OS wimp using
> OSLib bindings and it just works! Sooo nice! OO without C++ ugliness!"

There are thousands of interesting languages around that are
"cool" and "nice". And some of them once had RISC OS ports. Tcl.
Python. Lua. Ada. Forth. Java. Apart from Lua, none of those ports
have been kept up-to-date.

It is really one of the major RISC OS failings (back in the Acorn years)
that we never had a consolidated library - especially for the WIMP -
that was universally used by developers and multiple languages. The
Toolbox was a weak attempt. The amount of "reinventing the wheel"
amongst developers is staggering.

Steffen

--
Steffen Huber
hubersn Software - http://www.hubersn-software.com/


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Kendrick  
View profile   Translate to Translated (View Original)
 More options 20 Oct, 13:41
Newsgroups: comp.sys.acorn.programmer
From: Rob Kendrick <n...@rjek.com>
Date: Tue, 20 Oct 2009 13:41:11 +0100
Local: Tues 20 Oct 2009 13:41
Subject: Re: SWIs and BASIC file reading/writing in C++
On Tue, 20 Oct 2009 14:28:02 +0200

Steffen Huber <s...@huber-net.de> wrote:
> Apart from the basic flow stuff (if/switch, loops) and the curly
> braces, I can't think of much that you must know from C that you need
> in modern C++. If you use the STL and the standard lib, you don't need
> the pointer stuff and malloc and things. You don't need structs and
> unions. You don't need the preprocessor apart from import. You don't
> need the complicated C string stuff.

You'll end up with a really badly performing C++ program, though :)
And you missed pointers.  And what happens when you want to interface
with something from the C world.

> In short, everything that is difficult in C (and I talk here from
> a solution perspective, not from an implementation perspective -
> if you follow that line of argument, you should learn Assembler first,
> because it is and order of magnitude simpler than C) you do not need
> to know in C++.

Simpler in concept, but not simpler in use.

> If you stay within the bounds of "safe C++", I would say
> that C++ is actually simpler than C. Let's face it, for real
> world problems, C is a very complicated language, because you
> have to implement everything in a low-level manner with very
> little abstraction and safety to keep you out of trouble.

That's why we have libraries; just like you use in C++ to do these.

> > The problem is that it's almost impossible to avoid bizarre, complex
> > and difficult problems.  Most people don't even realise they've
> > stepped on a bomb.

> Oh, it is easily possible. There are very few things in C++ that
> look easy but are hard to understand.

And you end up with C with operator overloading.

> > Vala could be possible, Jan-Jaap van der Geer tweeted this recently;

> > "Playing around with a little Vala programming under RISC OS wimp
> > using OSLib bindings and it just works! Sooo nice! OO without C++
> > ugliness!"

> There are thousands of interesting languages around that are
> "cool" and "nice". And some of them once had RISC OS ports. Tcl.
> Python. Lua. Ada. Forth. Java. Apart from Lua, none of those ports
> have been kept up-to-date.

The nice approach of Vala is its simplicity, and its working.  It emits
C, so you can use your already existing libraries, and its support
library requirements are quite modest (in that, it depends on Glib, but
its use of Glib is quite simple, so is likely to be around for the
foreseeable future.)

It lacking any of the traditional code generators, OS bindings, or
anything at all that make porting future versions of the compiler
difficult, it should be much easier to keep it up to date.

Which is almost exactly the same reason Lua's still kept up to date;
it's simple and trivial to maintain once ported.

B.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan Graham Harston  
View profile   Translate to Translated (View Original)
 More options 20 Oct, 17:40
Newsgroups: comp.sys.acorn.programmer
From: j...@arcade.demon.co.uk (Jonathan Graham Harston)
Date: 20 Oct 2009 17:40:20 +0100
Local: Tues 20 Oct 2009 17:40
Subject: Re: SWIs and BASIC file reading/writing in C++

garethlock wrote:
> I understand the command side of things, but I need to be able to
> convert files written with BASICs PRINT# command. That is why I need
> either customised routines to do it, or how BASIC does it, so I can

Is the BBCFile library at http://mdfs.net/BLib/BBCFile informative
enough to trabslate into C? BBCFile implements PRINT# and INPUT# in
BASIC, so lets you read/write Acorn-style BASIC data files
regardless of the native implementation the interpreter happens to
use.

Otherwise, I could through some C code together to add to the VB
implementation.

--
J.G.Harston - j...@arcade.demon.co.uk - mdfs.net/User/JGH
There are three food groups: brown, green and ice cream.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mr John FO Evans  
View profile   Translate to Translated (View Original)
 More options 20 Oct, 23:39
Newsgroups: comp.sys.acorn.programmer
From: Mr John FO Evans <mi...@orpheusmail.co.uk>
Date: Tue, 20 Oct 2009 23:39:23 BST
Local: Tues 20 Oct 2009 23:39
Subject: Re: SWIs and BASIC file reading/writing in C++
In article <4f5ae3ac50.ja...@iyonix.lan>, James Peacock

<j.peacock.n...@googlemail.com> wrote:
> Even basic string manipulation is a pain in C, something as simple as
> concatenating two strings. Even BASIC can do it better for short
> strings. C++ at least offers you the fairly safe and easy to use
> std::string, which I think most C++ programmers would consider simple
> enough for a beginner to use. I can't say the same about C, it will at
> the least involve malloc, possibly free somewhere, memcpy or similar;
> and that doesn't even mention the explicit error handling or pointer
> ownership details.

What is wrong with strcat(s1,s2)??????

 OK the string library is limited - but it doesn't need much ingenuity to
extend it. Also pointer/array ownership can usually be controlled by the
program structure and need not involve malloc etc. if string arrays are
declared (As they are effectively in BASIC).

 If extensive use is made of malloc/free it is straightforward to provide
error checks and safe garbage collection without complicating the language.
Also with modern machines the time/memory overheads for doing this are small
for many applications.

Also it my opinion the more complex a language becomes:-

a) Simple minded programmers (like me) are less likely to understand what
they are doing.

b) As a consequence the more likely it is that features will be
misinterpreted by the programmer.

John

Oh by the way, C has a form of garbage collection in the shape of local
variables!

--
    _                     _________________________________________
   / \._._ |_  _     _  /'       Orpheus Internet Services
   \_/| |_)| |(/_|_|_> /          'Internet for Everyone'
_______ | ___________./       http://www.orpheusinternet.co.uk


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rob Kendrick  
View profile   Translate to Translated (View Original)
 More options 21 Oct, 00:38
Newsgroups: comp.sys.acorn.programmer
From: Rob Kendrick <n...@rjek.com>
Date: Wed, 21 Oct 2009 00:38:04 +0100
Local: Wed 21 Oct 2009 00:38
Subject: Re: SWIs and BASIC file reading/writing in C++
On Tue, 20 Oct 2009 23:39:23 BST
Mr John FO Evans <mi...@orpheusmail.co.uk> wrote:

> What is wrong with strcat(s1,s2)??????

It doesn't give you a compiler error for use of too many question marks?

More seriously, at least it teaches you what is actually happening.

>  OK the string library is limited - but it doesn't need much
> ingenuity to extend it. Also pointer/array ownership can usually be
> controlled by the program structure and need not involve malloc etc.
> if string arrays are declared (As they are effectively in BASIC).

Indeed; there are countless macro libraries out there to make C strings
safe and easy.

> Oh by the way, C has a form of garbage collection in the shape of
> local variables!

This is called the stack.  It's difficult to think of a language that
doesn't use the stack like this.

B.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 27   Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google