Re: A C Adventure: your comments are welcome



spinoza1111 wrote:

<snip>

OK, so here's how I represent strings:

struct TYPstring
{
long intSegmentLength;
char * strSegment;
void * usrLeftSegment;
void * usrRightSegment;
};

That is (das ist) a string is a binary tree of segments, giving it
unlimited length and avoiding Stupid Sentinels. Each segment is at
most 2^31 - 1 wide characters long, but there is no apriori bound to
the tree: therefore the above structure represents strings.

Two problems:

1. It seems I cannot include what I want to be a self-referential
struct inside a struct either as the thing itself or as a pointer
because either C or the Navia compiler is basically one-pass. I can't
do this in C Sharp either but can if I change the struct to a class.
So, void pointers raise their pretty little heads.

But: note that there's no point in a"void"ing void pointers in C
because C makes it easy to change pointer type. If there is no modern
try..catch in C then the only way of detecting whether you have a
pointer to a valid data type is to examine memory at the place where
the pointer points.

Look up any text on how to implement linked lists and don't use pointers to void. Then you have compile time checking.

2. With minimal assumptions (that is, minimal #includes) I default to
char and not wchar.

<snip>

If you want to use wchar_t then the hearder declaring it is one of the headers in the minimal set you need. So what you are say is...

I will use all headers I need, but no others
X is defined in a header which I am not using

So you are breaking your own rules and blaming C for the fact you are not following your rules.


So of your two problems, one was not knowing the normal method of doing a linked list and blaming the language for your ignorance, and the other is you not following your rules or doing what the language says you do in order to have what you want. So both problems are you.
--
Flash Gordon
.



Relevant Pages

  • Re: how to store list of varying types
    ... When there's a variable-length string, ... typedef struct { ... pointer null, and the second one the CString object. ... then have to finish constructing the packet by copying the two data objects ...
    (microsoft.public.vc.mfc)
  • Re: invalid pointer adress
    ... >> pointer causes the program to exit with a core dump. ... struct s2{void *p;}; ... int leseExterneHinweise_masch_storno ... typedef struct s_AusdatFeldbeschreibung ...
    (comp.lang.c)
  • Re: MVC in C++
    ... No Observer can handle ... > struct Observable ... > void notifyObservers() ... > string version; ...
    (comp.object)
  • Re: Model-View-Controller
    ... Type t to edit Title, v to edit Version, c to edit Credits. ... struct Observable ... void addObserver ... string version_caption; ...
    (alt.comp.lang.learn.c-cpp)
  • Re: MVC in C++
    ... Type t to edit Title, v to edit Version, c to edit Credits. ... struct Observable ... void addObserver ... string version_caption; ...
    (comp.object)