#17 Using C++

open
nobody
None
5
2004-02-14
2004-02-14
Anonymous
No

Hi,
I am still a senior in high school, and am thus just
learning programming. I learned the basics of C++, so I
pretty much understand the basics of C/C++
programming, but all I have takin in it is a first year
course and only know how to create console programs.
I know a little about classes and linked lists, but beyond
that I haven't learned. I want to create a program for
my TI 83+ that would be impossible in TI Basic and more
trouble than its worth in Assembly language, but
relatively easy in C++. I have been unable to find a
C++ compiler for Z80s, so I downloaded your C
compiler. I would be much more comfortable doing it in
C++, but can do it in C if I have to. What I am
wondering is if I can use library files (i.e. iostream.h)
from C++ with your compiler as long as I have all of the
neccessary include files (I have borland turbo C++, so I
have all of them), or if the compiler would have to be
designed to use them. One main thing I would like to
use is apstring, because that would be a lot easier than
pointers to character arrays. 1) Can I use these files
with this compiler as long as I include them all? 2)If not,
do you know of a C++ compiler I can get for free that
does Z80 files? Or 3) if I have to do it in C, do you
know of anything similar to apstring that can be used in
C, or can I use apstring.h and .cpp as an example to
create my own C version of it relatively easily? I don't
know exactly what from C++ I can and can't use in C.
It probably would have been better to learn C first, but
C++ was the class that was available. My email address
is kingjpk@yahoo.com. Thanks in advance for your time
and help,
James King

P.S. I have attached a copy of apstring.h and
apstring.cpp (they are in one text file because I cant
attach 2 files, but are seperated into the .h and .cpp
files.) incase you don't know what they are, they are
classes provided by the AP computer programming
program to simplify the process of learning C++.

Discussion

  • apstring.txt

     
    Attachments
  • Logged In: NO

    Since z88dk is a cross compiler from one system to, in this
    case, a TI 83 calculator, it has to use libraries written for the
    Z80 processor. Borland's Turbo C++ libraries are all designed
    for MS DOS targets, so they won't work with z88dk.

    Why not just use the string.h included with standard C?
    Sure, you have to work with pointers to keep track of the
    strings, but all the normal functionality is there.
    (concatenate, length, copy, etc.) Pointers are not
    intrinsically a difficult concept to grasp; some approaches to
    teaching them just lead to some unnecessary mystique.

    If you want to create a new library to do such things, you'll
    have to find (or write for yourself) a set of string
    management routines that will work with standard C.

    Unfortunately, functions cannot be members of a structure in
    C. Additionally, operator overloading is not available in C.
    Therefore, my initial reaction is that you probably cannot just
    convert the classes to a C format.

    It probably would be possible to create data structures
    containing data similar to the variables included in the AP
    string classes. However, you would have to change all the
    member functions to new functions that take the target
    structure as one argument, as well as any other arguments
    that were included in the class's member functions.

    eg. mystringclass::concat(const mystringclass src)
    becomes
    strcat(mystringstruct* dst, const mystringstruct src)

    Since operator overloading is not allowed, stuff like

    mystringclass operator = (mystringclass&)

    would have to be replaced by

    void copystring(mystringstruct* dest, const mystringstruct
    src)

    Also, remember that constructors and destructors are not
    available, so you'd have to remember to explicitly call
    functions to initialize the structures and clean up after
    yourself when you're done with them. (for example, at the
    end of every function, the automatic variables of type
    mystringstruct all have to be "destructed" manually.)