Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Generic programming in C.

204 views
Skip to first unread message

jacob navia

unread,
May 18, 2012, 5:14:35 AM5/18/12
to
When I presented an example of the interface here (thread CCL vs STL, a
comparison), many posters complained about the syntax:

int main(void)
{
List *L;
int data;

L = iList.Create(sizeof(int));

data = 0;
iList.Add(L,&data);
iList.PushFront(L,&data);
data = 2;
iList.InsertAt(L,1,&data);
// ...
}

It was said that passing a void pointer couldn't be checked by
the compiler (what is trure of course) and that the whole wasn't
very easy to use (maybe).

I have developed a "generic" approach using a parametized file.

For instance, if you want a list of integers, you write a small file
like this:

---------------------------intlist.c (the implementation)
#include "containers.h"
#undef DATA_TYPE
#define DATA_TYPE int
#include "listgen.c"
#undef DATA_TYPE

----------------------------intlist.h (the declarations)
#include "containers.h"
#undef DATA_TYPE
#define DATA_TYPE int
#include "listgen.h"
#undef DATA_TYPE

That's all. This defines following stuff:

A type called "intList" that implements ALL the functions
of the list container for the int data type. The requirements
for the data type are that it must be a value type, i.e. the
code assumes that it is passed by value. At the same time
the "iintList" interface is defined with the same entry
points as the generic list interface iList.

Besides it must be a single token, for instance for using
long long you must

typedef long long longlong;
#define DATA_TYPE longlong

Besides those two points, the file allows now to do as follows:

-------------------------------using specialized list container
#include "containers.h"
#include "intlist.h"
static int PrintInt(int data,void *extraArgs)
{
fprintf(extraArgs,"%d ",data);
}
int main(void)
{
intList *L;
int data;

L = iintList.Create(sizeof(int));
iintList.Add(L,0);
iintList.PushFront(L,0);
iintList.InsertAt(L,1,2);

iintList.Add(L,5);

iintList.Add(L,6);
iintList.Apply(L,PrintInt,stdout);
iintList.Finalize(L);
}

Note that the "Create" function still takes the same
arguments as the original generic one. I want to keep
all code compatible since it would be better to avoid code bloat.

Each instanstiated type adds 18.6K to the program (x86+gcc/OS X Mac)

If you have several types, code could be shared in many instances
since the data type remains compatible, and the signatures weren't
changed.

For the time being code is NOT shared.


What do you think?

jacob

Rui Maciel

unread,
May 18, 2012, 8:51:55 AM5/18/12
to
jacob navia wrote:

> What do you think?

Is the programmer forced to write a pair of source files for each data type
used in a list? And what happens when a programmer must use lists of
different data types in the same source file?


Rui Maciel

jacob navia

unread,
May 18, 2012, 9:01:20 AM5/18/12
to
Le 18/05/12 14:51, Rui Maciel a �crit :
The programmer is not "forced " to do anything. He is a free man and can
decide:

1) Use the generic interface with void pointers.
2) Use the generic interface with a special file for each type.
3) Abandon C and use C#

Note that solution (2) means he has to add the resulting object file to
a private library for the application where all those classes for
all the types are stored.

For instance in the Mac he would have to write

mycontainers.a: intList.c
gcc -c -Os intlist.c
ar -r mycontainers.a intlist.o

or something similar.


> And what happens when a programmer must use lists of
> different data types in the same source file?

Nothing. He just includes the header files for the different types.

But I see where you want to go:

Yes, I know. C++ is the best invention since sliced bread. I know.

BGB

unread,
May 18, 2012, 11:01:54 AM5/18/12
to
I once did vaguely similar using an extended preprocessor and block macros.

#defmacro FOO(type)
...
lots of stuff...
...
#endmacro

...

FOO(int)

the block-macro differed from #define mostly in that it could handle
larger globs of code and didn't need endless '\' characters.

there were lots of other features as well (such as delayed preprocessor
commands, ...).

IMO, it is a little nicer, but didn't really get lots of use since it is
an extra hassle to set up code to be passed through an extra tool prior
to compilation (unless it stood between make and the compiler or
something, which it didn't do).


otherwise:
passing parameters into specialized header files via #define is a trick
I have used before. it works I guess.

a particular example is this of the "main loop" stub for my 3D engine,
where due to technical reasons I ended up having to "hijack" main (or
WinMain), and a special header generates the main loop.

parameters are used for, among other things, setting GC options (initial
heap-size limits, ...) and indicating which functions to call (functions
are called at various locations in order to do whatever, such as set-up
or tear-down app, redraw the window, ...).


or such...

Ike Naar

unread,
May 18, 2012, 11:51:39 AM5/18/12
to
On 2012-05-18, jacob navia <ja...@spamsink.net> wrote:
> -------------------------------using specialized list container
> #include "containers.h"

Is this necessary, given that intlist.h includes containers.h ?

> #include "intlist.h"
> static int PrintInt(int data,void *extraArgs)
> {
> fprintf(extraArgs,"%d ",data);

Nit: PrintInt promises to return an int, but fails to do so.

> }
> int main(void)
> {
> intList *L;
> int data;
>
> L = iintList.Create(sizeof(int));
> iintList.Add(L,0);
> iintList.PushFront(L,0);
> iintList.InsertAt(L,1,2);
>
> iintList.Add(L,5);
>
> iintList.Add(L,6);
> iintList.Apply(L,PrintInt,stdout);
> iintList.Finalize(L);
> }
>
> Note that the "Create" function still takes the same
> arguments as the original generic one. I want to keep
> all code compatible since it would be better to avoid code bloat.

There is no need to supply the size of the data type to
iintList.Create(), because the function knows (or at least should now)
that the value must be sizeof(int).
The user is forced to specify a value: if the correct value is passed
it offers no new information to the function, if a wrong value is passed
it may lead to subtle runtime errors. Nonzero cost, zero benefit.

You say you want to avoid code bloat, but as far as I can tell, a
parameterless iintList.Create() needs to be no more than a minimal
wrapper around the generic iList.Create(),

intList *iintList.Create(void) { return iList.Create(sizeof(int)); }

That's not much code bloat.

Rui Maciel

unread,
May 18, 2012, 5:30:11 PM5/18/12
to
jacob navia wrote:

> The programmer is not "forced " to do anything. He is a free man and can
> decide:
>
> 1) Use the generic interface with void pointers.
> 2) Use the generic interface with a special file for each type.
> 3) Abandon C and use C#
>
> Note that solution (2) means he has to add the resulting object file to
> a private library for the application where all those classes for
> all the types are stored.
>
> For instance in the Mac he would have to write
>
> mycontainers.a: intList.c
> gcc -c -Os intlist.c
> ar -r mycontainers.a intlist.o
>
> or something similar.

So, basically your technique requires the programmer to add a couple source
files for each list that stores a different data type. Is this true?


> > And what happens when a programmer must use lists of
> > different data types in the same source file?
>
> Nothing. He just includes the header files for the different types.

Could you please provide an example where you use, say, 3 of your lists,
with each one handling a different data type?


Rui Maciel

jacob navia

unread,
May 18, 2012, 5:58:35 PM5/18/12
to
Le 18/05/12 23:30, Rui Maciel a écrit :
> So, basically your technique requires the programmer to add a couple source
> files for each list that stores a different data type. Is this true?
>
>

Well you can reduce all files to one if you wish:

#include "containers.h"
#undef DATA_TYPE
#define DATA_TYPE int
#include "listgen.h"
#undef DATA_TYPE


#define DATA_TYPE double
#include "listgen.h"
#undef DATA_TYPE

#define DATA_TYPE float
#include "listgen.h"
#undef DATA_TYPE


Lists for strings (wchar_t and plain char) are already provided. I will
deliver the package with all the basic data types already done
(int, double, etc).

But yes, in principmle you have to add those defines


>> > And what happens when a programmer must use lists of
>> > different data types in the same source file?
>>
>> Nothing. He just includes the header files for the different types.
>
> Could you please provide an example where you use, say, 3 of your lists,
> with each one handling a different data type?


#include "containers.h"
#undef DATA_TYPE
#define DATA_TYPE int
#include "listgen.h"
#undef DATA_TYPE


#define DATA_TYPE double
#include "listgen.h"
#undef DATA_TYPE

#define DATA_TYPE longlong
typedef long long longlong;
#include "listgen.h"
#undef DATA_TYPE


int main(void)
{
intList *L;
doubleList *D;
longlongList *LL;

L = intList.Create(sizeof(int))
D = doubleList.Create(sizeof(double));
LL = longlongList.Create(sizeof(longlong));

doubleList.Add(D,3.141592653);
longlongList.Add(LL,0xDEADBEEFULL);
// etc
}

Edward Rutherford

unread,
May 19, 2012, 2:34:40 AM5/19/12
to
jacob navia wrote:

> Le 18/05/12 14:51, Rui Maciel a écrit :
>> jacob navia wrote:
>>
>>> What do you think?
>>
>> Is the programmer forced to write a pair of source files for each data
>> type used in a list? And what happens when a programmer must use lists
>> of different data types in the same source file?
>>
>>
>> Rui Maciel
>
> The programmer is not "forced " to do anything. He is a free man

Sorry, but this sort of casual sexism really gets my goat - it
embarrasses our whole discipline.

It's no wonder that so few women pursue careers in software engineering
when this sort of neanderthal attitude is omnipresent, seeking to exclude
them.

Using gender-neutral language costs the author nothing and is simple
politeness.

IMO. YMMV.

//EPR

Kaz Kylheku

unread,
May 19, 2012, 2:39:53 AM5/19/12
to
Very well, let us continue. Where were we?
Ah yes, "He or she is a free man ..."

jacob navia

unread,
May 19, 2012, 3:08:24 AM5/19/12
to
Le 19/05/12 08:34, Edward Rutherford a écrit :
>> The programmer is not "forced " to do anything. He is a free man
> Sorry, but this sort of casual sexism really gets my goat - it
> embarrasses our whole discipline.


Look, I am not responsible for the sexism of the english
language. English is not my mother language but I think
that the generic word for human being is "man".

The dictionary says:

man:

1. an adult male person, as distinguished from a boy or a woman.
2.
a member of the species Homo sapiens or all the members of this species
collectively, without regard to sex: prehistoric man.

My mistake would have been that I used the "he" instead of he/she
because I tried to make the "he" compatible with the first
meaning of "man" and not the second.

I agree that there are less women than men in here, for instance
there isn't a single women in this group as far as I know, and
that this situation is bad.

In any case no sexism was intended.

jacob

Malcolm McLean

unread,
May 19, 2012, 5:12:13 AM5/19/12
to ja...@jspamsink.org
בתאריך יום שבת, 19 במאי 2012 08:08:24 UTC+1, מאת jacob navia:
>
> I agree that there are less women than men in here, for instance
> there isn't a single women in this group as far as I know, and
> that this situation is bad.
>
Because the truth is that very few women are interested in computer programming. There are many who are interested in careers in computer programming, but that's not the same thing, and comp.lang.c doesn't directly translate to a career benefit.

There are odd individual exceptions, of course, we we don't currently have one on the newsgroup.

Malcolm McLean

unread,
May 19, 2012, 5:08:13 AM5/19/12
to ja...@jspamsink.org
בתאריך יום שבת, 19 במאי 2012 08:08:24 UTC+1, מאת jacob navia:
>
> Look, I am not responsible for the sexism of the english
> language. English is not my mother language but I think
> that the generic word for human being is "man".
>
In English the male embraces the female. So we say "dog" unless we specifically mean a female dog, when we use "bitch", we call our country the "United Kingdom" even though we are currently ruled by a Queen, we man the barricades during our riots.

Some feminist-inclined women are trying to change this rule, so you'll often see constructions like s/he, or "he or she". But then they decide that it's still sexist to have the "he" first, so we have "she or he", and the whole thing collapses into self-consciousness. If you must use feminist langage, it's better to rewrite sentences with "they". So instead of "he must be a qualified draughtsman" "they must have a qualification in draughting technical drawings".

BartC

unread,
May 19, 2012, 6:52:49 AM5/19/12
to
"Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
message news:jp7eu0$eg9$1...@speranza.aioe.org...
> jacob navia wrote:

>> The programmer is not "forced " to do anything. He is a free man
>
> Sorry, but this sort of casual sexism really gets my goat - it
> embarrasses our whole discipline.
>
> It's no wonder that so few women pursue careers in software engineering
> when this sort of neanderthal attitude is omnipresent, seeking to exclude
> them.

> Using gender-neutral language costs the author nothing and is simple
> politeness.

I think there is a cost. You would either have to change half the English
language (which often uses 'man' in words to mean man or woman), or have to
write in stilted, obviously contrived language that will come across as
forced, especially in a field which *is* mostly men.

("It is one small step for Man - or Woman - ..." doesn't have quite the same
ring.)

--
Bartc

Jens Gustedt

unread,
May 19, 2012, 8:13:42 AM5/19/12
to ja...@jspamsink.org, jacob navia
Hello,

I already had expressed my ideas about this on how to do this with
macros in the other thread, I'll just try to give a brief summary.

Am 18.05.2012 11:14, schrieb jacob navia:
> I have developed a "generic" approach using a parametized file.
>
> For instance, if you want a list of integers, you write a small file
> like this:
>
> ---------------------------intlist.c (the implementation)
> #include "containers.h"
> #undef DATA_TYPE
> #define DATA_TYPE int
> #include "listgen.c"
> #undef DATA_TYPE

Instead of this if done with macros my "implementation" file for the
type int would simply contain

---------------------------intlist.c (the implementation)
#include "containers.h"

ILIST_DEFINE(int);


and the header file would just be

----------------------------intlist.h (the declarations)
#include "containers.h"

ILIST_DECLARE(int);


> That's all.

that's even less and would even be sort of readable, and less subject to
typos.

The code in containers would be slightly more difficult to read and
write (those macros can become a bit lenghty)

A user could just declare lists for different types without problems

#include "containers.h"

ILIST_DECLARE(int);
ILIST_DECLARE(unsigned);
ILIST_DECLARE(toto);
ILIST_DECLARE(toto*);

and would have to provide

ILIST_DEFINE(toto);
ILIST_DEFINE(toto*);

in exactly one of his compilation units. (Supposing that the ones for
the standard types are provided by the library.)


> This defines following stuff:

> A type called "intList" that implements ALL the functions
> of the list container for the int data type. The requirements
> for the data type are that it must be a value type, i.e. the
> code assumes that it is passed by value. At the same time
> the "iintList" interface is defined with the same entry
> points as the generic list interface iList.

I still don't get the point of this interface. I think that is is
substantially clearer and less error prone to write

intList_toto_create()

than

iintList.Create(sizeof(toto))

since the first version could give you stronger typing of the return
value. If for implementation reasons you'd like to have this all as
one generic list type under the hood (which can be a valid
implementation choice) this shouldn't concern the user of your library
and shouldn't influence on the interface.

If you want it as a functional expression in the type just define
something like

#if __STDC_VERSION__ < 201100L
# define intList_create(T) intList_ ## T ## _create()
#else
# define intList_create(T) _Generic((T){0}, int: intList_int_create,
unsigned: intList_unsigned_create, ...)()
#endif

"..." here for all other types that your interface is
implemented. That even would avoid to be dependent on the particular
"spelling" a user choses for T.

Jens

Ben Bacarisse

unread,
May 19, 2012, 8:52:41 AM5/19/12
to
"BartC" <b...@freeuk.com> writes:

> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
> message news:jp7eu0$eg9$1...@speranza.aioe.org...
>> jacob navia wrote:
>
>>> The programmer is not "forced " to do anything. He is a free man
>>
>> Sorry, but this sort of casual sexism really gets my goat - it
>> embarrasses our whole discipline.
>>
>> It's no wonder that so few women pursue careers in software engineering
>> when this sort of neanderthal attitude is omnipresent, seeking to exclude
>> them.
>
>> Using gender-neutral language costs the author nothing and is simple
>> politeness.
>
> I think there is a cost. You would either have to change half the English
> language (which often uses 'man' in words to mean man or woman), or have to
> write in stilted, obviously contrived language that will come across as
> forced, especially in a field which *is* mostly men.

You realize, I hope, that you are making the case for gender-neutral
language? Everyone who finds it stilted and contrived is evidence of
it's continued importance.

I never (knowingly) use gender-biased terms. Do you find my posts
stilted and contrived? If so, please say where because I am always on
the look-out for ways to improve my writing.

> ("It is one small step for Man - or Woman - ..." doesn't have quite the same
> ring.)

He intended to say (and has always claimed he did say) "That's one small
step for *a* man..." which has the benefit of being correct, as well as
being entirely gender-appropriate. Presumably you wanted to make a
point what followed.

--
Ben.

Ben Bacarisse

unread,
May 19, 2012, 9:15:10 AM5/19/12
to
Malcolm McLean <malcolm...@btinternet.com> writes:

> בתאריך יום שבת, 19 במאי 2012 08:08:24 UTC+1, מאת jacob navia:
>>
>> Look, I am not responsible for the sexism of the english
>> language. English is not my mother language but I think
>> that the generic word for human being is "man".
>>
> In English the male embraces the female. So we say "dog" unless we
> specifically mean a female dog, when we use "bitch", we call our
> country the "United Kingdom" even though we are currently ruled by a
> Queen, we man the barricades during our riots.

That's a good summary of the problem. In everyday language, to be
female is to be the other, the alternative, the notable case.

<snip polemic>
> ... it's better to rewrite sentences with
> "they". So instead of "he must be a qualified draughtsman" "they must
> have a qualification in draughting technical drawings".

That's a good suggestion and one I almost always use.

--
Ben.

Ben Bacarisse

unread,
May 19, 2012, 9:26:15 AM5/19/12
to
Kaz Kylheku <k...@kylheku.com> writes:

> On 2012-05-19, Edward Rutherford
> <edward.p.r...@REMOVETHIS.gmail.com>
<snip>
>> Using gender-neutral language costs the author nothing and is simple
>> politeness.
>
> Very well, let us continue. Where were we?
> Ah yes, "He or she is a free man ..."

If you feel you are on a roll, are there any other significant issues
you'd like to mock? Might as well get it all out in one thread...

--
Ben.

James Kuyper

unread,
May 19, 2012, 11:07:30 AM5/19/12
to
On 05/19/2012 05:08 AM, Malcolm McLean wrote:
...
> In English the male embraces the female.

The fact that it has done so in the past is no good reason for
continuing to do the same stupid thing in the present. Blind obedience
to that sexist tradition ironically leaves English with no way to
distinguish a reference exclusively to a male from a reference that
includes either a male or a female.
--
James Kuyper

Marco

unread,
May 19, 2012, 12:38:26 PM5/19/12
to
On Saturday, May 19, 2012 3:52:49 AM UTC-7, Bart wrote:
> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
> message news:jp7eu0$eg9$1...@speranza.aioe.org...
> > jacob navia wrote:
>
> >> The programmer is not "forced " to do anything. He is a free man

A programmer is not "forced " to do anything. You are free to do as you like.

> ("It is one small step for Man - or Woman - ..." doesn't have quite the same
> ring.)

"mankind" means all people

Kaz Kylheku

unread,
May 19, 2012, 2:06:58 PM5/19/12
to
On 2012-05-19, Marco <prenom...@yahoo.com> wrote:
> On Saturday, May 19, 2012 3:52:49 AM UTC-7, Bart wrote:
>> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
>> message news:jp7eu0$eg9$1...@speranza.aioe.org...
>> > jacob navia wrote:
>>
>> >> The programmer is not "forced " to do anything. He is a free man
>
> A programmer is not "forced " to do anything. You are free to do as you like.

That's a clumsy shift from third to first. I can hear the gears grinding.

--
If you ever need any coding done, I'm your goto man!

Ike Naar

unread,
May 19, 2012, 2:48:04 PM5/19/12
to
On 2012-05-19, Kaz Kylheku <k...@kylheku.com> wrote:
> On 2012-05-19, Marco <prenom...@yahoo.com> wrote:
>> On Saturday, May 19, 2012 3:52:49 AM UTC-7, Bart wrote:
>>> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
>>> message news:jp7eu0$eg9$1...@speranza.aioe.org...
>>> > jacob navia wrote:
>>>
>>> >> The programmer is not "forced " to do anything. He is a free man
>>
>> A programmer is not "forced " to do anything. You are free to do as you like.
>
> That's a clumsy shift from third to first. I can hear the gears grinding.

Third gear to second ;-)

Martin Shobe

unread,
May 19, 2012, 2:54:50 PM5/19/12
to
Kaz Kylheku wrote:

> On 2012-05-19, Marco <prenom...@yahoo.com> wrote:
>> On Saturday, May 19, 2012 3:52:49 AM UTC-7, Bart wrote:
>>> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
>>> message news:jp7eu0$eg9$1...@speranza.aioe.org...
>>> > jacob navia wrote:
>>>
>>> >> The programmer is not "forced " to do anything. He is a free man
>>
>> A programmer is not "forced " to do anything. You are free to do as you like.
>
> That's a clumsy shift from third to first. I can hear the gears grinding.
>
Second, not first, but still. Better probably would be third person
plural. In general, that's probably your best choice in similar
situations, since it has a gender neutral pronount that deosn't carry
negative connotations when referring to a person.

"Programmers are not "forced" to do anything. They are free to do as
they like."

Martin Shobe

BartC

unread,
May 19, 2012, 3:29:50 PM5/19/12
to
"Ben Bacarisse" <ben.u...@bsb.me.uk> wrote in message
news:0.54ca62c383286c998c16.2012...@bsb.me.uk...
> "BartC" <b...@freeuk.com> writes:
>
>> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in

>>> Using gender-neutral language costs the author nothing and is simple
>>> politeness.
>>
>> I think there is a cost.

> I never (knowingly) use gender-biased terms. Do you find my posts
> stilted and contrived? If so, please say where because I am always on
> the look-out for ways to improve my writing.

I'm sure your language is fine. But you're asking the wrong person, as I
don't really notice gender bias, especially in a technical group like this
where there is less scope for it.

I used to try and be gender-neutral, but it was too much trouble, and now I
don't really bother. If I'm talking about a builder, but don't know the
gender, I might use 'him'; if about someone's secretary, I might use 'her'.
The fact is, builders *are* normally men, and most secretaries *do* seem to
be women.

Then I might use 'he', 'his', 'him' etc as generic terms, where gender is
unknown or not relevant. It was in this latter sense that jacob was using
'he' and 'man'. And I bet hardly anyone noticed, or was offended, until Mr.
Rutherford draw attention to it.

(Or perhaps I should say Mr, Mrs, Miss, or Ms Rutherford; you never know.
Silly mistake; no wonder few parents call their daughters Edward, with
attitudes like mine..)

>> ("It is one small step for Man - or Woman - ..." doesn't have quite the
>> same
>> ring.)
>
> He intended to say (and has always claimed he did say) "That's one small
> step for *a* man..." which has the benefit of being correct, as well as
> being entirely gender-appropriate. Presumably you wanted to make a
> point what followed.

It was supposed to be humorous...

--
Bartc

jacob navia

unread,
May 19, 2012, 6:15:54 PM5/19/12
to
Le 18/05/12 23:30, Rui Maciel a écrit :
>
>
> So, basically your technique requires the programmer to add a couple source
> files for each list that stores a different data type. Is this true?
>
>
> Could you please provide an example where you use, say, 3 of your lists,
> with each one handling a different data type?
>
>


I answered both questions. It would be interesting to know your opinion.

Ben Bacarisse

unread,
May 19, 2012, 6:12:05 PM5/19/12
to
"BartC" <b...@freeuk.com> writes:

> "Ben Bacarisse" <ben.u...@bsb.me.uk> wrote in message
> news:0.54ca62c383286c998c16.2012...@bsb.me.uk...
>> "BartC" <b...@freeuk.com> writes:
>>
>>> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
>
>>>> Using gender-neutral language costs the author nothing and is simple
>>>> politeness.
>>>
>>> I think there is a cost.

Why did you snip the part where you describe the cost as language that
is stilted, obviously contrived and forced? It removes all the context
for my question and makes your evasion look less obvious.

>> I never (knowingly) use gender-biased terms. Do you find my posts
>> stilted and contrived? If so, please say where because I am always on
>> the look-out for ways to improve my writing.
>
> I'm sure your language is fine. But you're asking the wrong person, as I
> don't really notice gender bias, especially in a technical group like this
> where there is less scope for it.

Eh? You are the perfect person, since you claimed that the cost is "to
write in stilted, obviously contrived language that will come across as
forced"[1]. Can't you spot such things? If they are absent from my
posts (as you rather grudgingly admit) does that not suggest that you
are wrong.

<snip>

[1] I am going to assume that I have not succeeded in changing half the
English language -- the only other option you offered to gender-biased
terms.

--
Ben.

BartC

unread,
May 19, 2012, 7:13:20 PM5/19/12
to
"Ben Bacarisse" <ben.u...@bsb.me.uk> wrote in message
news:0.1042bc85651d5eb4a2ad.2012...@bsb.me.uk...
> "BartC" <b...@freeuk.com> writes:
>
>> "Ben Bacarisse" <ben.u...@bsb.me.uk> wrote in message
>> news:0.54ca62c383286c998c16.2012...@bsb.me.uk...
>>> "BartC" <b...@freeuk.com> writes:
>>>
>>>> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote
>>>> in
>>
>>>>> Using gender-neutral language costs the author nothing and is simple
>>>>> politeness.
>>>>
>>>> I think there is a cost.
>
> Why did you snip the part where you describe the cost as language that
> is stilted, obviously contrived and forced? It removes all the context
> for my question and makes your evasion look less obvious.
>
>>> I never (knowingly) use gender-biased terms. Do you find my posts
>>> stilted and contrived? If so, please say where because I am always on
>>> the look-out for ways to improve my writing.
>>
>> I'm sure your language is fine. But you're asking the wrong person, as I
>> don't really notice gender bias, especially in a technical group like
>> this
>> where there is less scope for it.
>
> Eh? You are the perfect person, since you claimed that the cost is "to
> write in stilted, obviously contrived language that will come across as
> forced"[1]. Can't you spot such things? If they are absent from my
> posts (as you rather grudgingly admit) does that not suggest that you
> are wrong.

OK. I said I don't notice gender bias, such as the combination of
"programmer" and "he". Like most people I would simply take that as being a
generic term meaning either "he" and "she". It's not necessary to use
examples such as these gleaned from other posts:

"he or she"
"he/she"
"s/he"
"she or he"
"they" (this one requiring the sentence to be reworked)

(I don't know to what 'free man' would be altered to; 'free person' just
sounds crass.)

Some of these I would notice, and I find them irritating, especially when
it's obvious that it *is* predominantly one or the other in any instance.

And when I'm writing this stuff myself, having to restructure grammar to
avoid bias is a distraction. So I only bother when talking about a third
person and do not wish to disclose their gender.

And no, I haven't particularly noticed you using language like this. So
perhaps you're better at it and/or make some extra effort. In that case,
there is some cost.

(BTW, in some languages, the word for "programmer" may have a gender. In
Italian for example, that appears to be masculine. Anyone trying to be
gender-neutral in such a language is going to have their work cut out...)

--
Bartc

pete

unread,
May 19, 2012, 7:15:20 PM5/19/12
to
Ben Bacarisse wrote:

> He intended to say
> (and has always claimed he did say)
> "That's one small step for *a* man..."

That's a tough claim to sell.

http://www.nasa.gov/connect/sounds/
http://www.nasa.gov/590330main_ringtone_smallStep.m4r

--
pete

boB

unread,
May 19, 2012, 9:38:01 PM5/19/12
to
On Sat, 19 May 2012 18:54:50 +0000 (UTC), Martin Shobe
<martin...@yahoo.com> wrote:

>Kaz Kylheku wrote:
>
>> On 2012-05-19, Marco <prenom...@yahoo.com> wrote:
>>> On Saturday, May 19, 2012 3:52:49 AM UTC-7, Bart wrote:
>>>> "Edward Rutherford" <edward.p.r...@REMOVETHIS.gmail.com> wrote in
>>>> message news:jp7eu0$eg9$1...@speranza.aioe.org...
>>>> > jacob navia wrote:
>>>>
>>>> >> The programmer is not "forced " to do anything. He is a free man
>>>
>>> A programmer is not "forced " to do anything. You are free to do as you like.
>>



Just make sre we all take into account the responses from the women
programmers on this news group. Especially the ones that have
responded to this post !

boB

Malcolm McLean

unread,
May 20, 2012, 6:42:48 AM5/20/12
to
בתאריך יום ראשון, 20 במאי 2012 00:13:20 UTC+1, מאת Bart:
>
> (BTW, in some languages, the word for "programmer" may have a gender. In
> Italian for example, that appears to be masculine. Anyone trying to be
> gender-neutral in such a language is going to have their work cut out...)
>
That's true in most languages. English is unusual in having natural gender (with the exception of countries and ships, gender always represents sex), and in having a very degenerate system of endings. Whilst we have some feminine endings (lioness, Freda, laddette), you can't generally tell the gender of a word from its ending. (Matron, sister, nun, queen, lady, vixen, bitch, sow, girl, aunt, mother, dame, madam, wife). In virtually all other languages you can.



Ben Bacarisse

unread,
May 20, 2012, 7:46:14 AM5/20/12
to
boB <K7IQ> writes:
<snip>
> Just make sre we all take into account the responses from the women
> programmers on this news group. Especially the ones that have
> responded to this post !

Out of interest... is your behavior largely determined by who is
commenting on it?

<snip>
--
Ben.

Rui Maciel

unread,
May 20, 2012, 12:57:39 PM5/20/12
to
jacob navia wrote:

> I answered both questions. It would be interesting to know your opinion.

In my opinion, your implementation actually looks nice. The #undef/#define
preprocessor trick might not be particularly easy on the eyes, but it may be
the best way to get around C's limitations. At least I'm not aware of
anyone coming up with a better solution.

If it was a part of C's standard library I would use it.

Keep up the good work, and don't feel discouraged for any lack of feedback,
or even any criticism which isn't particularly constructive.


Rui Maciel

nick_keigh...@hotmail.com

unread,
May 21, 2012, 5:34:50 AM5/21/12
to ja...@jspamsink.org
On Saturday, May 19, 2012 10:12:13 AM UTC+1, Malcolm McLean wrote:
> בתאריך יום שבת, 19 במאי 2012 08:08:24 UTC+1, מאת jacob navia:

> > I agree that there are less women than men in here, for instance
> > there isn't a single women in this group as far as I know, and
> > that this situation is bad.
>
> Because the truth is that very few women are interested in computer programming. There are many who are interested in careers in computer programming, but that's not the same thing,

really? seriously? How can you have a career in computer programming without an interest in programming? Can you have a career as a chef without an interest in cooking? I've known a few female programmers. What I find odd is that other contries seem (on a very small sample!) to have less gender bias than the UK.

I also had the odd experience at university of being asked by a south east asian moslem woman why so few english women studied compuer science...

nick_keigh...@hotmail.com

unread,
May 21, 2012, 5:38:14 AM5/21/12
to ja...@jspamsink.org
I find it particularly distracting when the pronoun is alternated.

"If the programmer finds himself in the situation..."
then a paragraph later
"An alternative she could use..."
Did he/she have major surgery between a paragraphs?

It seems to be American academics that beat themselves up most about this. The alternating gender stuff was actually stated as policy in the preface.

Rui Maciel

unread,
May 21, 2012, 6:46:54 AM5/21/12
to
nick_keigh...@hotmail.com wrote:

> really? seriously? How can you have a career in computer programming
> without an interest in programming? Can you have a career as a chef
> without an interest in cooking? I've known a few female programmers. What
> I find odd is that other contries seem (on a very small sample!) to have
> less gender bias than the UK.

The answer is yes. There are plenty of people who have chosen a career
exclusively due to financial reasons instead of having a honest interest in
the subject.

If that wasn't the case then we wouldn't have accountants.


Rui Maciel

James Kuyper

unread,
May 21, 2012, 6:53:46 AM5/21/12
to
On 05/21/2012 05:34 AM, nick_keigh...@hotmail.com wrote:
> On Saturday, May 19, 2012 10:12:13 AM UTC+1, Malcolm McLean wrote:
...
>> Because the truth is that very few women are interested in computer
>> programming. There are many who are interested in careers in
>> computer programming, but that's not the same thing,
>
> really? seriously? How can you have a career in computer programming
> without an interest in programming? Can you have a career as a chef
> without an interest in cooking?

Sure; lots of people pursue careers in fields that they're not
particularly interested in. Money is the most common reason. In fact,
one of the key purposes of money is to encourage more people to work at
certain jobs than would be willing to do so if it weren't for the high
salary paid to people who do those jobs.

You don't reach the top of a profession without having a real interest
in it, but the bottom of almost every profession is filled with people
who are not very interested in what they're doing for a living.
--
James Kuyper

Tim Rentsch

unread,
May 21, 2012, 1:25:39 PM5/21/12
to
Edward Rutherford <edward.p.r...@REMOVETHIS.gmail.com> writes:

> jacob navia wrote:
>
>> Le 18/05/12 14:51, Rui Maciel a @C3{A9}crit :
>>> jacob navia wrote:
>>>
>>>> What do you think?
>>>
>>> Is the programmer forced to write a pair of source files for each data
>>> type used in a list? And what happens when a programmer must use lists
>>> of different data types in the same source file?
>>>
>>>
>>> Rui Maciel
>>
>> The programmer is not "forced " to do anything. He is a free man
>
> Sorry, but this sort of casual sexism really gets my goat - [snip]

Billy or nanny?

Kaz Kylheku

unread,
May 21, 2012, 1:40:18 PM5/21/12
to
On 2012-05-21, nick_keigh...@hotmail.com <nick_keigh...@hotmail.com> wrote:
> On Saturday, May 19, 2012 10:12:13 AM UTC+1, Malcolm McLean wrote:
>> בתאריך יום שבת, 19 במאי 2012 08:08:24 UTC+1, מאת jacob navia:
>
>> > I agree that there are less women than men in here, for instance
>> > there isn't a single women in this group as far as I know, and
>> > that this situation is bad.
>>
>> Because the truth is that very few women are interested in computer
>> programming. There are many who are interested in careers in computer
>> programming, but that's not the same thing,
>
> really? seriously? How can you have a career in computer programming without
> an interest in programming?

Yes. It means that outside of the hours 9 to 5, Monday to Friday, you wouldn't
even think about doing programming, and the computer you have at home is
completely devoid of anything resembling a programming tool.

Malcolm's meaning is perfectly clear there.

> Can you have a career as a chef without an
> interest in cooking?

Absolutely. To someone, this can just be a stable job that earns money.

Enough money to eat out so you can avoid cooking when you come home.

>> There are odd individual exceptions, of course, we we don't currently have
>> one on the newsgroup.

There was that Alicia Carla Longstreet years ago, who turned out to be a
transgender person, originally male.

Kaz Kylheku

unread,
May 21, 2012, 1:42:38 PM5/21/12
to
On 2012-05-21, James Kuyper <james...@verizon.net> wrote:
> On 05/21/2012 05:34 AM, nick_keigh...@hotmail.com wrote:
>> On Saturday, May 19, 2012 10:12:13 AM UTC+1, Malcolm McLean wrote:
> ...
>>> Because the truth is that very few women are interested in computer
>>> programming. There are many who are interested in careers in
>>> computer programming, but that's not the same thing,
>>
>> really? seriously? How can you have a career in computer programming
>> without an interest in programming? Can you have a career as a chef
>> without an interest in cooking?
>
> Sure; lots of people pursue careers in fields that they're not
> particularly interested in. Money is the most common reason. In fact,
> one of the key purposes of money is to encourage more people to work at
> certain jobs than would be willing to do so if it weren't for the high
> salary paid to people who do those jobs.

Or, in some cases, if it were not for the meagre salary.

If a building has washrooms that need cleaning, you don't need to offer
a king's ransom to find someone willing to do it.

io_x

unread,
May 25, 2012, 4:39:36 AM5/25/12
to

"jacob navia" <ja...@spamsink.net> ha scritto nel messaggio
news:jp53tp$qk4$1...@speranza.aioe.org...
> When I presented an example of the interface here (thread CCL vs STL, a
> comparison), many posters complained about the syntax:
>
> int main(void)
> {
> List *L;
> int data;
>
> L = iList.Create(sizeof(int));
>
> data = 0;
> iList.Add(L,&data);
> iList.PushFront(L,&data);
> data = 2;
> iList.InsertAt(L,1,&data);
> // ...
> }
>
> It was said that passing a void pointer couldn't be checked by
> the compiler (what is trure of course) and that the whole wasn't
> very easy to use (maybe).

i add alt.lang.asm because 90% function are in x86 asm

i not agree type safety too
i think 1 runtime check is better than 1000 type check compile time

than possible i condider equivalent u32, u32* and void* and u8* and i8*...

the place of start is the examle of C++ stl list
found in book
"C++ Tecniche avanzate di programmazione"
autori: H.M. Deitel, P.J. Deitel pag 370

first i wrote the assembly function than the remain C ones
it is a double concatecated list, useful for stack queue too

all list2 function return -1 for error and set the carry flag too

/* Test per Liste e array --------*/
/*
#define uns unsigned
#define u32 unsigned
#define u64 unsigned __int64
#define i32 int
#define u16 unsigned short
#define u8 unsigned char
#define i8 char
#define i16 short
#define long_long __int64
#define sdC __stdcall
#define ooo cout
#define S sizeof
#define MM Malloc_m
#define FF Free_m

#define F for
#define R return
#define W while
#define G goto

*/

i32 __stdcall pelm(u32 elm){R P("0x%x(%u) ", elm, elm)<=0 ? -1 : 0; }

i32 List2Print(u32* list, u8* testo)
{u32 r=0, cr=0;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=ListNelem(list); if(r==-1) G vai;
if(testo){if(P("%s",testo)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1(list, pelm);
if(P("]" )<=0) R -1;
R r?-1:0;
}


i32 __stdcall pdouble(u32 elm)
{u32 cr=0;
GetSizeFast((void*) elm); cr+=cf(); // controlla che venga da malloc
if(cr){P("Err"); R -1;}
R P("%.0f ", *(double*)elm)<=0 ? -1 : 0;
}


i32 List2PrintD(u32* list, u8* msg)
{u32 r=0, cr=0;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=ListNelem(list); if(r==-1) G vai;
if(msg)
{if( P("%s", msg)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1(list, pdouble); cr+=(r!=0);
if(P("]" )<=0) R -1;
if(cr) G vai;
R r;
}

u8* DaiMemDouble(double a)
{double *r;
r=(double*)MM(S *r); if(r==0) R 0;
*r=a;
R (u8*)r;
}

u32* List2PushAT(u32* lista, u8* a)
{if(a==0) R (u32*) -1; R List2PushT(lista, (u32)a);}

u32* List2PushAH(u32* lista, u8* a)
{if(a==0) R (u32*) -1; R List2PushH(lista, (u32)a);}


i32 cmpu32(u32 a, u32 b)
{ if(a> b) R 1;
else if(a==b) R 0;
else R -1;
}

i32 cmpadouble(u32 aa, u32 bb)
{double *a, *b;

a=(double*)(aa); b=(double*)(bb);
if(a==0||b==0) R -3;
// P("%.1f<>%.1f ", *a, *b);
if(*a> *b) R 1;
else if(*a==*b) R 0;
else R -1;
}

i32 __stdcall cmp4 (u32 elm){i32 r=elm; r-=4; R r; }

i32 __stdcall cmpd4(u32 elm)
{double *r;
r=(double*)elm;
if( r==0) R -3;
if(*r==4.0) R 0;
R 1;
}


/*
Esempio parallelo a quello che usa le C++ STL
del libro: "C++ Tecniche avanzate di programmazione"
autori: H.M. Deitel, P.J. Deitel pag 370
*/
// funzione test per il tipo base u32 per liste
i32 listeProvaLibro(void)
{u32 lista[2]={0}, lista1[2]={0}, cr, r,*pr;
u32 arrayu32[10]={2,6,4,8, 2}, var, *pr1;

cr=0;
// inserisce u32 in lista
r=(u32) List2PushH(lista, 1); cr+=(r==-1);
r=(u32) List2PushH(lista, 2); cr+=(r==-1);
r=(u32) List2PushT(lista, 4); cr+=(r==-1);
r=(u32) List2PushT(lista, 3); cr+=(r==-1);
r=List2Print(lista,"lista di u32: lista="); cr+=(r==-1); P("\n");
if(cr){P("Errore"); ex: List2Free(lista); R -1;}

// ordina la lista
r=List2Sortu32(lista);cr+=(r==-1);
r=List2Print(lista,"dopo ordinamento lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore1"); G ex;}

// inserisce gli elementi dell'array arrayu32[]
pr=ListHead(lista1) ;cr+=((u32)pr==-1);
r=List2InsArrDopo(lista1,pr,arrayu32,4);cr+=(r==-1);
r=List2Print(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr){P("Errore2"); ex1: List2Free(lista1); G ex;}


// rimuove gli elementi di "lista1"
// e li inserisce in coda ad "lista"
pr=ListTail(lista) ; cr+=((u32)pr==-1);
r=List2SpostaLista(lista, pr, lista1); cr+=(r==-1);
r=List2Print(lista, "lista+=lista1 lista=" );cr+=(r==-1);
r=List2Print(lista1," lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore3\n"); G ex1;}

//ordina i valori di lista
r=List2Sortu32(lista); cr+=(r==-1);
r=List2Print(lista,"dopo ordine lista="); cr+=(r==-1); P("\n");
if(cr) {P("Errore4\n"); G ex1;}


// inserisce gli elementi dell'array arrayu32[] in lista1
pr=ListHead(lista1) ;cr+=((u32)pr==-1);
r=List2InsArrDopo(lista1,pr,arrayu32,4);cr+=(r==-1);
r=List2Sortu32(lista1); cr+=(r==-1);
r=List2Print(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore5\n"); G ex1;}

// rimuove gli elementi di "lista1"
// e li inserisce ordinati in "lista"
r=List2MergeLista(lista, lista1, cmpu32) ;cr+=(r==-1);
r=List2Print(lista, "Dopo merge lista=" );cr+=(r==-1);
r=List2Print(lista1, " lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore6\n"); G ex1;}

// rimuove l'elemento in testa e in coda
r=List2PopH(&var, lista); cr+=(r==-1);
r=List2PopT(&var, lista); cr+=(r==-1);
r=List2Print(lista, "Dopo 2pop lista=");cr+=(r==-1); P("\n");
if(cr) {P("Errore7\n"); G ex1;}

// elimina i doppioni in lista
r=List2Unici(lista, cmpu32); cr+=(r==-1);
r=List2Print(lista, "Dopo aver eliminato gli unici lista=");
cr+=(r==-1); P("\n");
if(cr) {P("Errore8\n"); G ex1;}

// scambia le liste lista e lista1
r=List2SwapListe(lista, lista1) ; cr+=(r==-1);
r=List2Print(lista, "Dopo lo swap lista=" ); cr+=(r==-1);
r=List2Print(lista1, " lista1=" ); cr+=(r==-1); P("\n");
if(cr) {P("Errore9\n"); G ex1;}

// lista= lista1
pr =ListHead(lista1); cr+=((u32)pr ==-1);
pr1=ListTail(lista1); cr+=((u32)pr1==-1);
r=List2AssegnaNodi(lista, pr, pr1, lista1); cr+=(r==-1);
r=List2Print(lista, "Dopo l'assegnamento lista=" ); P("\n");
cr+=(r==-1);
if(cr) {P("Errore10\n"); G ex1;}

// rimuove gli elementi di lista1 e li inserisce ordinati in lista
r=List2MergeLista(lista, lista1, cmpu32) ; cr+=(r==-1);
r=List2Print(lista, "Dopo lista+=lista1 lista=" ); cr+=(r==-1);
r=List2Controlla(lista) ; cr+=(r==-1);
r=List2Print(lista1, " Lista1="); cr+=(r==-1); P("\n");
r=List2Controlla(lista1) ; cr+=(r==-1);
if(cr) {P("Errore11\n"); G ex1;}

// rimuove l'elemento 4 dal "lista"
r=List2RimuoviSe(lista, cmp4); cr+=(r==-1);
r=List2Print(lista, "Lista dopo rimuovi 4 lista=" );
cr+=(r==-1); P("\n");
if(cr) {P("Errore12\n"); G ex1;}

// inserisce gli elementi dell'array arrayu32[]
pr=ListHead(lista1) ;cr+=((u32)pr==-1);
r=List2InsArrDopo(lista1,pr,arrayu32,5);cr+=(r==-1);
r=List2Print(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore13\n"); G ex1;}

// cerca dopo il nodo di indirizzo var; var=0 significa inizia da head
var=0;
r=List2FindNext(lista1, &var, 2, cmpu32); cr+=(r==-1);
if(r==0) {P("Trovato nodo=0x%x, *nodo+E=%u\n", var, *(u32*)(var+8) );}
r=List2FindNext(lista1, &var, 2, cmpu32); cr+=(r==-1);
if(r==0) {P("Trovato nodo=0x%x, *nodo+E=%u\n", var, *(u32*)(var+8) );}
r=List2FindNext(lista1, &var, 2, cmpu32); cr+=(r==-1);
if(r==0) {P("Trovato nodo=0x%x, *nodo+E=%u\n", var, *(u32*)(var+8) );}
r=List2FindNext(lista1, &var, 2, cmpu32); cr+=(r==-1);
if(cr) {P("Errore14\n"); G ex1;}

r=List2Free(lista ); cr+=(r==-1); r=List2Free(lista1);cr+=cf();
P("Alla fine r=%u cr=0\n", r, cr);
R 0;
}


/*
Esempio parallelo a quello che usa le C++ STL
del libro: "C++ Tecniche avanzate di programmazione"
autori: H.M. Deitel, P.J. Deitel pag 370
*/
// funzione test per il tipo double per liste
i32 listeProvaLibroDouble(void)
{double arrayd32[10]={2.0,6.0,4.0,8.0, 2.0}, m, *pd;
u32 lista[2]={0}, lista1[2]={0}, cr, r, var, var1, *pr, *pr1;

cr=0;
// inserisce double in lista
r=(u32) List2PushAH(lista, DaiMemDouble(1.0)); cr+=(r==-1);
r=(u32) List2PushAH(lista, DaiMemDouble(2.0)); cr+=(r==-1);
r=(u32) List2PushAT(lista, DaiMemDouble(4.0)); cr+=(r==-1);
r=(u32) List2PushAT(lista, DaiMemDouble(3.0)); cr+=(r==-1);

r=List2PrintD(lista,"lista di double: lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore"); ex: List2FreeNodiDaMalloc(lista); R -1;}

// ordina la lista
r=List2Sort(lista, cmpadouble); cr+=(r==-1);
r=List2PrintD(lista,"dopo ordinamento lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore1"); G ex;}


// inserisce gli elementi dell'array arrayd32[]
pr=ListHead(lista1); cr+=((u32)pr==-1);
r =List2InsArrDopoA(lista1,pr, (u32*) arrayd32,4, S(double));
cr+=(r==-1);
r=List2PrintD(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr){P("Errore2"); ex1: List2FreeNodiDaMalloc(lista1); G ex;}

// rimuove gli elementi di "lista1"
// e li inserisce in coda ad "lista"
pr=ListTail(lista) ; cr+=((u32)pr==-1);
r =List2SpostaLista(lista, pr, lista1); cr+=(r==-1);
r =List2PrintD(lista, "lista+=lista1 lista=" );cr+=(r==-1);
r =List2PrintD(lista1," lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore3\n"); G ex1;}

//ordina i valori di lista
r= List2Sort(lista, cmpadouble); cr+=(r==-1);
r=List2PrintD(lista,"dopo ordine lista="); cr+=(r==-1); P("\n");
if(cr) {P("Errore4\n"); G ex1;}

// inserisce gli elementi dell'array arrayd32[] in lista1
pr=ListHead(lista1); cr+=((u32)pr==-1);
r =List2InsArrDopoA(lista1,pr,(u32*)arrayd32,4, S(double) );
cr+=(r==-1);
r =List2Sort(lista1, cmpadouble); cr+=(r==-1);
r =List2PrintD(lista1,"dopo ins arr lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore5\n"); G ex1;}

// rimuove gli elementi di "lista1"
// e li inserisce ordinati in "lista"
r=List2MergeLista(lista, lista1, cmpadouble);cr+=(r==-1);
r=List2PrintD(lista, "Dopo merge lista=" ); cr+=(r==-1);
r=List2PrintD(lista1, " lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore6\n"); G ex1;}

// rimuove l'elemento in testa e in coda
r=List2PopH((u32*) &pd, lista); cr+=(r==-1); FF(pd);
r=List2PopT((u32*) &pd, lista); cr+=(r==-1); FF(pd);
r=List2PrintD(lista, "Dopo 2pop lista=");cr+=(r==-1); P("\n");
if(cr) {P("Errore7\n"); G ex1;}

// elimina i doppioni in lista
r=List2UniciA(lista, cmpadouble); cr+=(r==-1);
r=List2PrintD(lista, "Dopo aver eliminato gli unici lista=");
cr+=(r==-1); P("\n");
if(cr) {P("Errore8\n"); G ex1;}

// scambia le liste lista e lista1
r=List2SwapListe(lista, lista1) ; cr+=(r==-1);
r=List2PrintD(lista, "Dopo lo swap lista=" ); cr+=(r==-1);
r=List2PrintD(lista1, " lista1=" ); cr+=(r==-1); P("\n");
if(cr) {P("Errore9\n"); G ex1;}

// lista= lista1
pr =ListHead(lista1); cr+=((u32)pr ==-1);
pr1=ListTail(lista1); cr+=((u32)pr1==-1);
r=List2AssegnaNodiA(lista, pr, pr1, lista1, S(double));
cr+=(r==-1);
r=List2PrintD(lista, "Dopo l'assegnamento lista=" );
cr+=(r==-1);
r=List2PrintD(lista, " lista1=" ); P("\n");
cr+=(r==-1);
if(cr) {P("Errore10\n"); G ex1;}

// rimuove gli elementi di lista1 e li inserisce ordinati in lista
r=List2MergeLista(lista, lista1, cmpadouble); cr+=(r==-1);
r=List2PrintD(lista, "Merge lista1 in lista; lista=" );
cr+=(r==-1);
r=List2Controlla(lista); cr+=(r==-1);
r=List2PrintD(lista1, " Lista1=");cr+=(r==-1); P("\n");
r=List2Controlla(lista1); cr+=(r==-1);
if(cr) {P("Errore11\n"); G ex1;}

// rimuove l'elemento 4.0 dal "lista"
r=List2RimuoviSeA(lista, cmpd4); cr+=(r==-1);
r=List2PrintD(lista, "Lista dopo rimuovi 4.0 lista=" );
cr+=(r==-1); P("\n");
if(cr) {P("Errore12\n"); G ex1;}

// inserisce gli elementi dell'array arrayd32[]
pr=ListHead(lista1) ;cr+=((u32)pr==-1);
r =List2InsArrDopoA(lista1,pr, (u32*) arrayd32,5, S(double));
cr+=(r==-1);
r=List2PrintD(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore13\n"); G ex1;}

// cerca dopo il nodo di indirizzo var; var=0 significa inizia da head
m=2.0;
r=List2FindNext(lista1, &var, (u32) &m, cmpadouble); cr+=(r==-1);
if(r==0) {var1=*(u32*)(var+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", var, *(double*)var1);
}
r=List2FindNext(lista1, &var, (u32) &m, cmpadouble); cr+=(r==-1);
if(r==0){var1=*(u32*)(var+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", var, *(double*)var1);
}
r=List2FindNext(lista1, &var, (u32) &m, cmpadouble); cr+=(r==-1);
if(r==0){var1=*(u32*)(var+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", var, *(double*)var1);
}
r=List2FindNext(lista1, &var, (u32) &m, cmpadouble); cr+=(r==-1);
if(r==0){var1=*(u32*)(var+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", var, *(double*)var1);
}
if(cr) {P("Errore14\n"); G ex1;}

r=List2FreeNodiDaMalloc(lista) ;cr+=(r==-1);
r=List2FreeNodiDaMalloc(lista1);cr+=(r==-1);
P("Alla fine r=%u cr=%u\n", r, cr);

R 0;
}

lista di u32: lista=[ 0x2(2) 0x1(1) 0x4(4) 0x3(3) ]
dopo ordinamento lista=[ 0x1(1) 0x2(2) 0x3(3) 0x4(4) ]
dopo ins array lista1=[ 0x2(2) 0x6(6) 0x4(4) 0x8(8) ]
lista+=lista1 lista=[ 0x1(1) 0x2(2) 0x3(3) 0x4(4) 0x2(2) 0x6(6) 0x4(4) 0x8(8) ]
l
ista1=[ ]
dopo ordine lista=[ 0x1(1) 0x2(2) 0x2(2) 0x3(3) 0x4(4) 0x4(4) 0x6(6) 0x8(8) ]
dopo ins array lista1=[ 0x2(2) 0x4(4) 0x6(6) 0x8(8) ]
Dopo merge lista=[ 0x1(1) 0x2(2) 0x2(2) 0x2(2) 0x3(3) 0x4(4) 0x4(4) 0x4(4)
0x6(6)
0x6(6) 0x8(8) 0x8(8) ] lista1=[ ]
Dopo 2pop lista=[ 0x2(2) 0x2(2) 0x2(2) 0x3(3) 0x4(4) 0x4(4) 0x4(4) 0x6(6) 0x6(6)
0
x8(8) ]
Dopo aver eliminato gli unici lista=[ 0x2(2) 0x3(3) 0x4(4) 0x6(6) 0x8(8) ]
Dopo lo swap lista=[ ] lista1=[ 0x2(2) 0x3(3) 0x4(4) 0x6(6) 0x8(8) ]
Dopo l'assegnamento lista=[ 0x2(2) 0x3(3) 0x4(4) 0x6(6) 0x8(8) ]
Dopo lista+=lista1 lista=[ 0x2(2) 0x2(2) 0x3(3) 0x3(3) 0x4(4) 0x4(4) 0x6(6)
0x6(6)
0x8(8) 0x8(8) ] Lista1=[ ]
Lista dopo rimuovi 4 lista=[ 0x2(2) 0x2(2) 0x3(3) 0x3(3) 0x6(6) 0x6(6) 0x8(8)
0x8(
8) ]
dopo ins array lista1=[ 0x2(2) 0x6(6) 0x4(4) 0x8(8) 0x2(2) ]
Trovato nodo=0x32E508, *nodo+E=2
Trovato nodo=0x32E3E8, *nodo+E=2
Alla fine r=0 cr=0
lista di double: lista=[ 2 1 4 3 ]
dopo ordinamento lista=[ 1 2 3 4 ]
dopo ins array lista1=[ 2 6 4 8 ]
lista+=lista1 lista=[ 1 2 3 4 2 6 4 8 ] lista1=[ ]
dopo ordine lista=[ 1 2 2 3 4 4 6 8 ]
dopo ins arr lista1=[ 2 4 6 8 ]
Dopo merge lista=[ 1 2 2 2 3 4 4 4 6 6 8 8 ] lista1=[ ]
Dopo 2pop lista=[ 2 2 2 3 4 4 4 6 6 8 ]
Dopo aver eliminato gli unici lista=[ 2 3 4 6 8 ]
Dopo lo swap lista=[ ] lista1=[ 2 3 4 6 8 ]
Dopo l'assegnamento lista=[ 2 3 4 6 8 ] lista1=[ 2 3 4 6 8 ]
Merge lista1 in lista; lista=[ 2 2 3 3 4 4 6 6 8 8 ] Lista1=[ ]
Lista dopo rimuovi 4.0 lista=[ 2 2 3 3 6 6 8 8 ]
dopo ins array lista1=[ 2 6 4 8 2 ]
Trovato nodo=0x32E408, *nodo+E=2.0
Trovato nodo=0x32DFB8, *nodo+E=2.0
Alla fine r=0 cr=0




Ian Collins

unread,
May 25, 2012, 5:04:17 AM5/25/12
to
On 05/25/12 08:39 PM, io_x wrote:

> #define uns unsigned

Some people never learn, or maybe never stop trolling?

--
Ian Collins

Robert Wessel

unread,
May 25, 2012, 10:45:21 AM5/25/12
to
On Fri, 25 May 2012 10:39:36 +0200, "io_x" <a...@b.c.invalid> wrote:

>
>"jacob navia" <ja...@spamsink.net> ha scritto nel messaggio
>news:jp53tp$qk4$1...@speranza.aioe.org...
>> When I presented an example of the interface here (thread CCL vs STL, a
>> comparison), many posters complained about the syntax:
>>
>> int main(void)
>> {
>> List *L;
>> int data;
>>
>> L = iList.Create(sizeof(int));
>>
>> data = 0;
>> iList.Add(L,&data);
>> iList.PushFront(L,&data);
>> data = 2;
>> iList.InsertAt(L,1,&data);
>> // ...
>> }
>>
>> It was said that passing a void pointer couldn't be checked by
>> the compiler (what is trure of course) and that the whole wasn't
>> very easy to use (maybe).
>
>i add alt.lang.asm because 90% function are in x86 asm
>
>i not agree type safety too
>i think 1 runtime check is better than 1000 type check compile time


That's absurd - half a century of software engineering practice
clearly shows that catching an error at runtime is hugely more costly
than catching it at compile time. Of course not all errors can be
caught at compile time, but if possible, it's *far* better to do so,
and type safety helps with that a great deal.

io_x

unread,
May 25, 2012, 1:29:54 PM5/25/12
to

"io_x" <a...@b.c.invalid> ha scritto nel messaggio
news:4fbf4405$0$1382$4faf...@reader1.news.tin.it...
> // cerca dopo il nodo di indirizzo var; var=0 significa inizia da head
> m=2.0;

i forgot to write "var=0;"; the error is not cach because it seems
the not initializated value of var in runtime here is ... 0

io_x

unread,
May 25, 2012, 1:31:54 PM5/25/12
to

"Robert Wessel" <robert...@yahoo.com> ha scritto nel messaggio
news:hh6vr7t9jhg7r3gs2...@4ax.com...
+ one century of informatic without understand loop with
jump are better than
loops with while() and for()...



io_x

unread,
May 25, 2012, 2:06:00 PM5/25/12
to

"Robert Wessel" <robert...@yahoo.com> ha scritto nel messaggio
news:hh6vr7t9jhg7r3gs2...@4ax.com...
> On Fri, 25 May 2012 10:39:36 +0200, "io_x" <a...@b.c.invalid> wrote:
>>i add alt.lang.asm because 90% function are in x86 asm
>>
>>i not agree type safety too
>>i think 1 runtime check is better than 1000 type check compile time
>
>
> That's absurd - half a century of software engineering practice
> clearly shows that catching an error at runtime is hugely more costly
> than catching it at compile time.

yes i not read good... yes it is more costly
but error it can find the compiler are 0.00001%

> Of course not all errors can be
> caught at compile time, but if possible, it's *far* better to do so,
> and type safety helps with that a great deal.

even if one use one language with no type safety...
if there is some type size error [the only one that here count...]
than the OS or the heap manager find the out o bound problem and
teminate the prog so the error is out as soon it verify
or it is one big chance they[os and malloc] find it...

or pehraps one could debug if *(double*)a is not a double
mem rapresentation...
or the right number...[the prog ont give the right result]



Johannes Bauer

unread,
May 26, 2012, 6:16:35 AM5/26/12
to
On 25.05.2012 10:39, io_x wrote:

> i32 __stdcall pelm(u32 elm){R P("0x%x(%u) ", elm, elm)<=0 ? -1 : 0; }

Good god. I sure hope we never end up in the same company coding in a
project together. I'd strangle you for the above, promised.

Best regards,
Joe

--
>> Wo hattest Du das Beben nochmal GENAU vorhergesagt?
> Zumindest nicht öffentlich!
Ah, der neueste und bis heute genialste Streich unsere großen
Kosmologen: Die Geheim-Vorhersage.
- Karl Kaos über Rüdiger Thomas in dsa <hidbv3$om2$1...@speranza.aioe.org>

nick_keigh...@hotmail.com

unread,
May 26, 2012, 6:27:12 AM5/26/12
to
On Saturday, May 19, 2012 7:34:40 AM UTC+1, Edward Rutherford wrote:
> jacob navia wrote:
> > Le 18/05/12 14:51, Rui Maciel a écrit :

> >> Is the programmer forced to write a pair of source files for each data
> >> type used in a list? And what happens when a programmer must use lists
> >> of different data types in the same source file?
> >
> > The programmer is not "forced " to do anything. He is a free man
>
> Sorry, but this sort of casual sexism really gets my goat - it
> embarrasses our whole discipline.

sorry^W this sort of cheap reflexive political correctness gets on *my* goat.

> It's no wonder that so few women pursue careers in software engineering
> when this sort of neanderthal attitude is omnipresent, seeking to exclude
> them.

are you serious? Or is this some sort of parody?

> Using gender-neutral language costs the author nothing and is simple
> politeness.
>
> IMO. YMMV.
>
> //EPR

"I am not a number, I am a free man" was a cult British TV show perhaps Jacob was paraphrashing

nick_keigh...@hotmail.com

unread,
May 26, 2012, 6:30:22 AM5/26/12
to
On Saturday, May 19, 2012 7:34:40 AM UTC+1, Edward Rutherford wrote:

> It's no wonder that so few women pursue careers in software engineering
> when this sort of neanderthal attitude is omnipresent, seeking to exclude
> them.

While we are being all PC it should be noted the Neanderthals had larger brains than us, buried their dead and looked after their disabled and elderly. Quite why you feel able to take cheap shots at them to furthur your politi-social aims is quite beyond me.

Ian Collins

unread,
May 26, 2012, 7:06:41 AM5/26/12
to
On 05/26/12 10:16 PM, Johannes Bauer wrote:
> On 25.05.2012 10:39, io_x wrote:
>
>> i32 __stdcall pelm(u32 elm){R P("0x%x(%u) ", elm, elm)<=0 ? -1 : 0; }
>
> Good god. I sure hope we never end up in the same company coding in a
> project together. I'd strangle you for the above, promised.

You'd have to join a (long) queue...

--
Ian Collins

Rod Pemberton

unread,
May 26, 2012, 8:03:26 AM5/26/12
to
"Ian Collins" <ian-...@hotmail.com> wrote in message
news:a2908i...@mid.individual.net...
> On 05/25/12 08:39 PM, io_x wrote:
>
> > #define uns unsigned
>
> Some people never learn, or maybe never stop trolling?
>

Apparently, over the many years he has posted assembly to c.l.c., you
*never* read *any* of his assembly code. If so, you'd know his preference
for extreme terseness. I.e., that #define should not be a shock to you in
the least.

He wrote his own assembly language. It's syntax is so terse, sparse, or
compact that even skilled assembly programmers can't understand it. It's
too cryptic.

It's like some of the obscure languages described here:
http://esolangs.org/wiki/Main_Page


Rod Pemberton



nick_keigh...@hotmail.com

unread,
May 26, 2012, 7:58:38 AM5/26/12
to
try that one on comp.lang.lisp
people will argue that since complete compile type correctness is impossible to acheive it isn'tworth doing it at all. That tagging values with type at runtime is a more complete check. Though I'll argue either end of almost any argument (found abandoned in the wild and raised by lawyers) I'm not quite up to that one. Worth a go though...

Kaz Kylheku

unread,
May 26, 2012, 10:14:10 AM5/26/12
to
On 2012-05-26, Johannes Bauer <dfnson...@gmx.de> wrote:
> On 25.05.2012 10:39, io_x wrote:
>
>> i32 __stdcall pelm(u32 elm){R P("0x%x(%u) ", elm, elm)<=0 ? -1 : 0; }
>
> Good god. I sure hope we never end up in the same company coding in a
> project together.

I do not suspect that io_x is employable.

io_x

unread,
May 26, 2012, 11:34:29 AM5/26/12
to

"io_x" <a...@b.c.invalid> ha scritto nel messaggio
news:4fbf4405$0$1382$4faf...@reader1.news.tin.it...
> than possible i condider equivalent u32, u32* and void* and u8* and i8*...
...
> u32* List2PushAT(u32* lista, u8* a)
> {if(a==0) R (u32*) -1; R List2PushT(lista, (u32)a);}
>
> u32* List2PushAH(u32* lista, u8* a)
> {if(a==0) R (u32*) -1; R List2PushH(lista, (u32)a);}

if used with List2PushAT(lista, malloc(n) )
they have a memory leak...
so better something as
u32 List2PushAT(u32* lista, u8* a)
{u32 r;
if(a==0) R -1;
if(NotMallocched(a)) R -1;
if( (r=List2PushT(lista, (u32)a))== -1)
Free(a);
R r;
}

i consider a varible u32 enouhgt for store one address u8*...

/* Test per Liste e array --------*/
/*
#define uns unsigned
#define u32 unsigned
#define u64 unsigned __int64
#define i32 int
#define u16 unsigned short
#define u8 unsigned char
#define i8 char
#define i16 short
#define long_long __int64
#define sdC __stdcall
#define ooo cout
#define S sizeof
#define MM Malloc_m
#define FF Free_m

#define F for
#define R return
#define W while
#define G goto

*/

i32 __stdcall pelm(u32 elm){R P("%u ", elm)<=0 ? -1 : 0; }

i32 List2Pu32(u32* list, u8* testo)
{u32 r=0, cr=0;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=List2Nelem(list); if(r==-1) G vai;
if(testo){if(P("%s",testo)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1(list, pelm);
if(P("]" )<=0) R -1;
R r?-1:0;
}


i32 __stdcall pdouble(u8* elm)
{u32 cr=0;
GetSizeFast(elm); cr+=cf(); // controlla che venga da malloc
if(cr){P("Err"); R -1;}
R P("%.0f ", *(double*)elm)<=0 ? -1 : 0;
}


i32 List2Pdouble(u32* list, u8* msg)
{u32 r=0, cr=0;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=List2NelemA(list); if(r==-1) G vai;
if(msg)
{if( P("%s", msg)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1A(list, pdouble); cr+=(r!=0);
if(P("]" )<=0) R -1;
if(cr) G vai;
R r;
}

u8* DaiMemDouble(double a)
{double *r;
r=(double*)MM(S *r); if(r==0) R 0;
*r=a;
R (u8*)r;
}

i32 cmpu32(u32 a, u32 b)
{ if(a> b) R 1;
else if(a==b) R 0;
else R -1;
}

i32 cmpadouble(u8* aa, u8* bb)
{double *a, *b;

if(aa==0||bb==0) R -3;
a=(double*)(aa); b=(double*)(bb);
// P("%.1f<>%.1f ", *a, *b);
if(*a> *b) R 1;
else if(*a==*b) R 0;
else R -1;
}

i32 __stdcall cmp4 (u32 elm){i32 r=elm; r-=4; R r; }

i32 __stdcall cmpd4(u8* elm)
{double *r;
if(elm==0) R -3;
r=(double*)elm;
if(*r==4.0) R 0;
R 1;
}

/*
Esempio parallelo a quello che usa le C++ STL
del libro: "C++ Tecniche avanzate di programmazione"
autori: H.M. Deitel, P.J. Deitel pag 370
*/
// funzione test per il tipo base u32 per liste
i32 listeProvaLibro(void)
{u32 lista[2]={0}, lista1[2]={0}, cr, r, r1;
u32 arrayu32[10]={2,6,4,8, 2}, var;
u8 *pr, *pr1;

cr=0;
// inserisce u32 in lista
r=List2PushH(lista, 1); cr+=(r==-1);
r=List2PushH(lista, 2); cr+=(r==-1);
r=List2PushT(lista, 4); cr+=(r==-1);
r=List2PushT(lista, 3); cr+=(r==-1);
r=List2Pu32(lista,"lista di u32: lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore"); ex: List2Free(lista); R -1;}

// ordina la lista
r=List2Sortu32(lista); cr+=(r==-1);
r=List2Pu32(lista,"dopo ordinamento lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore1"); G ex;}

// inserisce gli elementi dell'array arrayu32[]
r=List2Head(lista1); cr+=(r==-1);
r=List2InsArrDopo(lista1,(u8*)r,arrayu32,4);
cr+=(r==-1);
r=List2Pu32(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr){P("Errore2"); ex1: List2Free(lista1); G ex;}


// rimuove gli elementi di "lista1"
// e li inserisce in coda ad "lista"
r=List2Tail(lista); cr+=(r==-1);
r=List2SpostaLista(lista,(u8*)r, lista1); cr+=(r==-1);
r=List2Pu32(lista, "lista+=lista1 lista=" ); cr+=(r==-1);
r=List2Pu32(lista1," lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore3\n"); G ex1;}

//ordina i valori di lista
r=List2Sortu32(lista); cr+=(r==-1);
r=List2Pu32(lista,"dopo ordine lista="); cr+=(r==-1); P("\n");
if(cr) {P("Errore4\n"); G ex1;}


// inserisce gli elementi dell'array arrayu32[] in lista1
r=List2Head(lista1); cr+=(r==-1);
r=List2InsArrDopo(lista1, (u8*)r,arrayu32,4); cr+=(r==-1);
r=List2Sortu32(lista1); cr+=(r==-1);
r=List2Pu32(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore5\n"); G ex1;}

// rimuove gli elementi di "lista1"
// e li inserisce ordinati in "lista"
r=List2MergeLista(lista, lista1, cmpu32); cr+=(r==-1);
r=List2Pu32(lista, "Dopo merge lista=" );cr+=(r==-1);
r=List2Pu32(lista1, " lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore6\n"); G ex1;}

// rimuove l'elemento in testa e in coda
r=List2PopH(&var, lista); cr+=(r==-1);
r=List2PopT(&var, lista); cr+=(r==-1);
r=List2Pu32(lista, "Dopo 2pop lista=");cr+=(r==-1); P("\n");
if(cr) {P("Errore7\n"); G ex1;}

// elimina i doppioni in lista
r=List2Unici(lista, cmpu32); cr+=(r==-1);
r=List2Pu32(lista, "Dopo aver eliminato gli unici lista=");
cr+=(r==-1); P("\n");
if(cr) {P("Errore8\n"); G ex1;}

// scambia le liste lista e lista1
r=List2SwapListe(lista, lista1); cr+=(r==-1);
r=List2Pu32(lista, "Dopo lo swap lista=" );
cr+=(r==-1);
r=List2Pu32(lista1, " lista1=" ); cr+=(r==-1); P("\n");
if(cr) {P("Errore9\n"); G ex1;}

// lista= lista1
r =List2Head(lista1); cr+=(r ==-1);
r1=List2Tail(lista1); cr+=(r1==-1);
r=List2AssegnaNodi(lista,(u8*)r,(u8*)r1, lista1);
cr+=(r==-1);
r=List2Pu32(lista, "Dopo l'assegnamento lista=" ); P("\n");
cr+=(r==-1);
if(cr) {P("Errore10\n"); G ex1;}

// rimuove gli elementi di lista1 e li inserisce ordinati in lista
r=List2MergeLista(lista, lista1, cmpu32); cr+=(r==-1);
r=List2Pu32(lista, "Dopo lista+=lista1 lista=" ); cr+=(r==-1);
r=List2Controlla(lista); cr+=(r==-1);
r=List2Pu32(lista1, " Lista1="); cr+=(r==-1); P("\n");
r=List2Controlla(lista1); cr+=(r==-1);
if(cr) {P("Errore11\n"); G ex1;}

// rimuove l'elemento 4 dal "lista"
r=List2RimuoviSe(lista, cmp4); cr+=(r==-1);
r=List2Pu32(lista, "Lista dopo rimuovi 4 lista=" );
cr+=(r==-1); P("\n");
if(cr) {P("Errore12\n"); G ex1;}

// inserisce gli elementi dell'array arrayu32[]
r=List2Head(lista1); cr+=(r==-1);
r=List2InsArrDopo(lista1,(u8*)r,arrayu32,5);cr+=(r==-1);
r=List2Pu32(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore13\n"); G ex1;}

// cerca dopo il nodo di indirizzo var; var=0 significa inizia da head
pr=0;
r=List2FindNext(lista1, &pr, 2, cmpu32); cr+=(r==-1);
if(r==0) {P("Trovato nodo=0x%x, *nodo+E=%u\n", pr, *(u32*)(pr+8) );}
r=List2FindNext(lista1, &pr, 2, cmpu32); cr+=(r==-1);
if(r==0) {P("Trovato nodo=0x%x, *nodo+E=%u\n", pr, *(u32*)(pr+8) );}
r=List2FindNext(lista1, &pr, 2, cmpu32); cr+=(r==-1);
if(r==0) {P("Trovato nodo=0x%x, *nodo+E=%u\n", pr, *(u32*)(pr+8) );}
r=List2FindNext(lista1, &pr, 2, cmpu32); cr+=(r==-1);
if(cr) {P("Errore14\n"); G ex1;}

r=List2Free(lista ); cr+=(r==-1); r=List2Free(lista1);cr+=(r==-1);
P("Alla fine r=%u cr=0\n", r, cr);
R 0;
}


/*
Esempio parallelo a quello che usa le C++ STL
del libro: "C++ Tecniche avanzate di programmazione"
autori: H.M. Deitel, P.J. Deitel pag 370
*/
// funzione test per il tipo double per liste
i32 listeProvaLibroDouble(void)
{double arrayd32[10]={2.0,6.0,4.0,8.0, 2.0}, m,*pd;
u32 lista[2]={0}, lista1[2]={0}, cr, r, r1, var, var1;
u8 *pr, *pr1;
cr=0;
// inserisce double in lista
r=List2PushHA(lista, DaiMemDouble(1.0)); cr+=(r==-1);
r=List2PushHA(lista, DaiMemDouble(2.0)); cr+=(r==-1);
r=List2PushTA(lista, DaiMemDouble(4.0)); cr+=(r==-1);
r=List2PushTA(lista, DaiMemDouble(3.0)); cr+=(r==-1);

r=List2Pdouble(lista,"lista di double: lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore"); ex: List2FreeA(lista); R -1;}

// ordina la lista
r=List2SortA(lista, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista,"dopo ordinamento lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore1"); G ex;}


// inserisce gli elementi dell'array arrayd32[]
r=List2HeadA(lista1); cr+=(r==-1);
r=List2InsArrDopoA(lista1, (u8*)r, (u8*) arrayd32,4, S(double));
cr+=(r==-1);
r=List2Pdouble(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr){P("Errore2"); ex1: List2FreeA(lista1); G ex;}

// rimuove gli elementi di "lista1"
// e li inserisce in coda ad "lista"
r=List2TailA(lista); cr+=(r==-1);
r=List2SpostaListaA(lista, (u8*)r, lista1); cr+=(r==-1);
r=List2Pdouble(lista, "lista+=lista1 lista=" );cr+=(r==-1);
r=List2Pdouble(lista1," lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore3\n"); G ex1;}

//ordina i valori di lista
r=List2SortA(lista, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista,"dopo ordine lista="); cr+=(r==-1); P("\n");
if(cr) {P("Errore4\n"); G ex1;}

// inserisce gli elementi dell'array arrayu32[] in lista1
r=List2HeadA(lista1); cr+=(r==-1);
r=List2InsArrDopoA(lista1,(u8*)r,(u8*)arrayd32,4, S(double) );
cr+=(r==-1);
r=List2SortA(lista1, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista1,"dopo ins arr lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore5\n"); G ex1;}

// rimuove gli elementi di "lista1"
// e li inserisce ordinati in "lista"
r=List2MergeListaA(lista, lista1, cmpadouble);cr+=(r==-1);
r=List2Pdouble(lista, "Dopo merge lista=" ); cr+=(r==-1);
r=List2Pdouble(lista1, " lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore6\n"); G ex1;}

// rimuove l'elemento in testa e in coda
r=List2PopHA(&pr, lista); cr+=(r==-1); FF(pr);
r=List2PopTA(&pr, lista); cr+=(r==-1); FF(pr);
r=List2Pdouble(lista, "Dopo 2pop lista=");cr+=(r==-1); P("\n");
if(cr) {P("Errore7\n"); G ex1;}

// elimina i doppioni in lista
r=List2UniciA(lista, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista, "Dopo aver eliminato gli unici lista=");
cr+=(r==-1); P("\n");
if(cr) {P("Errore8\n"); G ex1;}

// scambia le liste lista e lista1
r=List2SwapListeA(lista, lista1); cr+=(r==-1);
r=List2Pdouble(lista, "Dopo lo swap lista=" ); cr+=(r==-1);
r=List2Pdouble(lista1, " lista1=" ); cr+=(r==-1); P("\n");
if(cr) {P("Errore9\n"); G ex1;}

// lista= lista1
r =List2HeadA(lista1); cr+=(r ==-1);
r1=List2TailA(lista1); cr+=(r1==-1);
r =List2AssegnaNodiA(lista,(u8*)r,(u8*) r1, lista1, S(double));
cr+=(r==-1);
r=List2Pdouble(lista, "Dopo l'assegnamento lista=" );
cr+=(r==-1);
r=List2Pdouble(lista, " lista1=" ); P("\n");
cr+=(r==-1);
if(cr) {P("Errore10\n"); G ex1;}

// rimuove gli elementi di lista1 e li inserisce ordinati in lista
r=List2MergeListaA(lista, lista1, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista, "Merge lista1 in lista; lista=" );
cr+=(r==-1);
r=List2ControllaA(lista); cr+=(r==-1);
r=List2Pdouble(lista1, " Lista1=");cr+=(r==-1); P("\n");
r=List2ControllaA(lista1); cr+=(r==-1);
if(cr) {P("Errore11\n"); G ex1;}

// rimuove l'elemento 4.0 dal "lista"
r=List2RimuoviSeA(lista, cmpd4); cr+=(r==-1);
r=List2Pdouble(lista, "Lista dopo rimuovi 4.0 lista=" );
cr+=(r==-1); P("\n");
if(cr) {P("Errore12\n"); G ex1;}

// inserisce gli elementi dell'array arrayd32[]
r=List2HeadA(lista1); cr+=(r==-1);
r=List2InsArrDopoA(lista1, (u8*)r, (u8*)arrayd32,5, S(double));
cr+=(r==-1);
r=List2Pdouble(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr) {P("Errore13\n"); G ex1;}

// cerca dopo il nodo di indirizzo var; var=0 significa inizia da head
m=2.0; pr=0;
r=List2FindNextA(lista1, &pr, (u8*) &m, cmpadouble); cr+=(r==-1);
if(r==0) {pr1=*(u8**)(pr+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", pr, *(double*)pr1);
}
r=List2FindNextA(lista1, &pr, (u8*) &m, cmpadouble); cr+=(r==-1);
if(r==0){pr1=*(u8**)(pr+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", pr, *(double*)pr1);
}
r=List2FindNextA(lista1, &pr, (u8*) &m, cmpadouble); cr+=(r==-1);
if(r==0){pr1=*(u8**)(pr+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", pr, *(double*)pr1);
}
r=List2FindNextA(lista1, &pr, (u8*) &m, cmpadouble); cr+=(r==-1);
if(r==0){pr1=*(u8**)(pr+8);
P("Trovato nodo=0x%x, *nodo+E=%.1f\n", pr, *(double*)pr1);
}
if(cr) {P("Errore14\n"); G ex1;}

r=List2FreeA(lista) ;cr+=(r==-1);
r=List2FreeA(lista1);cr+=(r==-1);
P("Alla fine r=%u cr=%u\n", r, cr);

R 0;
}
lista di u32: lista=[ 2 1 4 3 ]
dopo ordinamento lista=[ 1 2 3 4 ]
dopo ins array lista1=[ 2 6 4 8 ]
lista+=lista1 lista=[ 1 2 3 4 2 6 4 8 ] lista1=[ ]
dopo ordine lista=[ 1 2 2 3 4 4 6 8 ]
dopo ins array lista1=[ 2 4 6 8 ]
Dopo merge lista=[ 1 2 2 2 3 4 4 4 6 6 8 8 ] lista1=[ ]
Dopo 2pop lista=[ 2 2 2 3 4 4 4 6 6 8 ]
Dopo aver eliminato gli unici lista=[ 2 3 4 6 8 ]
Dopo lo swap lista=[ ] lista1=[ 2 3 4 6 8 ]
Dopo l'assegnamento lista=[ 2 3 4 6 8 ]
Dopo lista+=lista1 lista=[ 2 2 3 3 4 4 6 6 8 8 ] Lista1=[ ]
Lista dopo rimuovi 4 lista=[ 2 2 3 3 6 6 8 8 ]
dopo ins array lista1=[ 2 6 4 8 2 ]
Trovato nodo=0x44E508, *nodo+E=2
Trovato nodo=0x44E3E8, *nodo+E=2
Alla fine r=0 cr=0
lista di double: lista=[ 2 1 4 3 ]
dopo ordinamento lista=[ 1 2 3 4 ]
dopo ins array lista1=[ 2 6 4 8 ]
lista+=lista1 lista=[ 1 2 3 4 2 6 4 8 ] lista1=[ ]
dopo ordine lista=[ 1 2 2 3 4 4 6 8 ]
dopo ins arr lista1=[ 2 4 6 8 ]
Dopo merge lista=[ 1 2 2 2 3 4 4 4 6 6 8 8 ] lista1=[ ]
Dopo 2pop lista=[ 2 2 2 3 4 4 4 6 6 8 ]
Dopo aver eliminato gli unici lista=[ 2 3 4 6 8 ]
Dopo lo swap lista=[ ] lista1=[ 2 3 4 6 8 ]
Dopo l'assegnamento lista=[ 2 3 4 6 8 ] lista1=[ 2 3 4 6 8 ]
Merge lista1 in lista; lista=[ 2 2 3 3 4 4 6 6 8 8 ] Lista1=[ ]
Lista dopo rimuovi 4.0 lista=[ 2 2 3 3 6 6 8 8 ]
dopo ins array lista1=[ 2 6 4 8 2 ]
Trovato nodo=0x44E408, *nodo+E=2.0
Trovato nodo=0x44DFB8, *nodo+E=2.0
Alla fine r=0 cr=0



Ian Collins

unread,
May 26, 2012, 3:57:41 PM5/26/12
to
On 05/27/12 12:03 AM, Rod Pemberton wrote:
> "Ian Collins"<ian-...@hotmail.com> wrote in message
> news:a2908i...@mid.individual.net...
>> On 05/25/12 08:39 PM, io_x wrote:
>>
>>> #define uns unsigned
>>
>> Some people never learn, or maybe never stop trolling?
>>
>
> Apparently, over the many years he has posted assembly to c.l.c., you
> *never* read *any* of his assembly code. If so, you'd know his preference
> for extreme terseness. I.e., that #define should not be a shock to you in
> the least.

I also stop reading its C as soon as I see those ridiculous defines.

--
Ian Collins

io_x

unread,
May 27, 2012, 4:36:49 AM5/27/12
to

"io_x" <a...@b.c.invalid> ha scritto nel messaggio
news:4fbf4405$0$1382$4faf...@reader1.news.tin.it...
>
> u8* DaiMemDouble(double a)
> {double *r;
> r=(double*)MM(S *r); if(r==0) R 0;
> *r=a;
> R (u8*)r;
> }

in few word constructor of element is above
destructor free() function...

i think it is need a distructor in the form

u8* __stdcall DestructorDoubleElement(u8* mem)
{if(isMalloccated(mem)) R -1;
free(mem); R 0;
}

and at end of the routine it would be something as:

List2FreeA1(lista, DestructorDoubleElement);

it would be OO? :)
what function is need for compete to stl C++?


Harry Vaderchi

unread,
May 27, 2012, 7:26:35 AM5/27/12
to
On Sat, 26 May 2012 13:03:26 +0100, Rod Pemberton
<do_no...@notemailntt.cmm> wrote:

> "Ian Collins" <ian-...@hotmail.com> wrote in message
> news:a2908i...@mid.individual.net...
>> On 05/25/12 08:39 PM, io_x wrote:
>>
>> > #define uns unsigned
>>
>> Some people never learn, or maybe never stop trolling?
>>
>
> Apparently, over the many years he has posted assembly to c.l.c., you
> *never* read *any* of his assembly code. If so, you'd know his
> preference
> for extreme terseness. I.e., that #define should not be a shock to you
> in
> the least.
>
> He wrote his own assembly language. It's syntax is so terse, sparse, or
> compact that even skilled assembly programmers can't understand it. It's
> too cryptic.
>
I'm not skilled, but I did read one once!; It was for the maze solving
Hugi compo
(the last one ever?) 2009.

> It's like some of the obscure languages described here:
> http://esolangs.org/wiki/Main_Page
>
>
> Rod Pemberton
>
>
>


--
[dash dash space newline 4line sig]

Albi CNU

io_x

unread,
May 28, 2012, 5:26:38 AM5/28/12
to

"io_x" <a...@b.c.invalid> ha scritto nel messaggio
news:4fc0f6c2$0$1390$4faf...@reader1.news.tin.it...
>

>> than possible i condider equivalent u32, u32* and void* and u8* and i8*...

do you like the OOP version...
// costruttore; per errore 0
u8* sdC dcst(void) {R (u8*)MM(S(double));}
// distruttore; per errore -1
u32 sdC ddst(u8* a) {R FF(a)?-1:0;}
// funzione di copia; per errore -1
u32 sdC dcpy(u8* d, u8* o){R MmrCpy(d, o, S(double))==0?-1:0;}
r=List2InsArrDopo(lista1,(u8*)r,arrayu32,4*4);
cr+=(r==-1);
r=List2Pu32(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr){P("Errore2"); ex1: List2Free(lista1); G ex;}


// rimuove gli elementi di "lista1"
// e li inserisce in coda ad "lista"
r=List2Tail(lista); cr+=(r==-1);
r=List2SpostaLista(lista,(u8*)r, lista1); cr+=(r==-1);
r=List2Pu32(lista, "lista+=lista1 lista=" ); cr+=(r==-1);
r=List2Pu32(lista1," lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore3\n"); G ex1;}

//ordina i valori di lista
r=List2Sortu32(lista); cr+=(r==-1);
r=List2Pu32(lista,"dopo ordine lista="); cr+=(r==-1); P("\n");
if(cr) {P("Errore4\n"); G ex1;}


// inserisce gli elementi dell'array arrayu32[] in lista1
r=List2Head(lista1); cr+=(r==-1);
r=List2InsArrDopo(lista1, (u8*)r,arrayu32,4*4); cr+=(r==-1);
r=List2InsArrDopo(lista1,(u8*)r,arrayu32,5*4);cr+=(r==-1);
r=List2CreA(lista, S(double), dcst, ddst, dcpy);
if(r==-1) R -1;
r=List2CreA(lista1, S(double), dcst, ddst, dcpy);
if(r==-1) {ex: List2FreeA(lista); R -1;}

// inserisce double in lista
m=1.0; r=List2PushHA(lista, (u8*)&m); cr+=(r==-1);
m=2.0; r=List2PushHA(lista, (u8*)&m); cr+=(r==-1);
m=4.0; r=List2PushTA(lista, (u8*)&m); cr+=(r==-1);
m=3.0; r=List2PushTA(lista, (u8*)&m); cr+=(r==-1);

r=List2Pdouble(lista,"lista di double: lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore"); ex1: List2FreeA(lista1); G ex;}

// ordina la lista
r=List2SortA(lista, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista,"dopo ordinamento lista=");
cr+=(r==-1); P("\n");
if(cr){P("Errore1"); G ex1;}

// inserisce gli elementi dell'array arrayd32[]
r=List2HeadA(lista1); cr+=(r==-1);
r=List2InsArrDopoA(lista1, (u8*)r, (u8*) arrayd32,4*S(double));
cr+=(r==-1);
r=List2Pdouble(lista1,"dopo ins array lista1=");
cr+=(r==-1);P("\n");
if(cr){P("Errore2"); G ex1;}

// rimuove gli elementi di "lista1"
// e li inserisce in coda ad "lista"
r=List2TailA(lista); cr+=(r==-1);
r=List2SpostaListaA(lista, (u8*)r, lista1); cr+=(r==-1);
r=List2Pdouble(lista, "lista+=lista1 lista=" );cr+=(r==-1);
r=List2Pdouble(lista1," lista1="); cr+=(r==-1); P("\n");
if(cr) {P("Errore3\n"); G ex1;}

//ordina i valori di lista
r=List2SortA(lista, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista,"dopo ordine lista="); cr+=(r==-1); P("\n");
if(cr) {P("Errore4\n"); G ex1;}

// inserisce gli elementi dell'array arrayu32[] in lista1
r=List2HeadA(lista1); cr+=(r==-1);
r=List2InsArrDopoA(lista1,(u8*)r,(u8*)arrayd32,4*S(double) );
r =List2AssegnaNodiA(lista,(u8*)r,(u8*) r1, lista1);
cr+=(r==-1);
r=List2Pdouble(lista, "Dopo l'assegnamento lista=" );
cr+=(r==-1);
r=List2Pdouble(lista, " lista1=" ); P("\n");
cr+=(r==-1);
if(cr) {P("Errore10\n"); G ex1;}

// rimuove gli elementi di lista1 e li inserisce ordinati in lista
r=List2MergeListaA(lista, lista1, cmpadouble); cr+=(r==-1);
r=List2Pdouble(lista, "Merge lista1 in lista; lista=" );
cr+=(r==-1);
r=List2ControllaA(lista); cr+=(r==-1);
r=List2Pdouble(lista1, " Lista1=");cr+=(r==-1); P("\n");
r=List2ControllaA(lista1); cr+=(r==-1);
if(cr) {P("Errore11\n"); G ex1;}

// rimuove l'elemento 4.0 dal "lista"
r=List2RimuoviSeA(lista, cmpd4); cr+=(r==-1);
r=List2Pdouble(lista, "Lista dopo rimuovi 4.0 lista=" );
cr+=(r==-1); P("\n");
if(cr) {P("Errore12\n"); G ex1;}

// inserisce gli elementi dell'array arrayd32[]
r=List2HeadA(lista1); cr+=(r==-1);
r=List2InsArrDopoA(lista1, (u8*)r, (u8*)arrayd32,5*S(double));
Trovato nodo=0x26E4E8, *nodo+E=2
Trovato nodo=0x26E3C8, *nodo+E=2
Alla fine r=0 cr=0
lista di double: lista=[ 2 1 4 3 ]
dopo ordinamento lista=[ 1 2 3 4 ]
dopo ins array lista1=[ 2 6 4 8 ]
lista+=lista1 lista=[ 1 2 3 4 2 6 4 8 ] lista1=[ ]
dopo ordine lista=[ 1 2 2 3 4 4 6 8 ]
dopo ins arr lista1=[ 2 4 6 8 ]
Dopo merge lista=[ 1 2 2 2 3 4 4 4 6 6 8 8 ] lista1=[ ]
Dopo 2pop lista=[ 2 2 2 3 4 4 4 6 6 8 ]
Dopo aver eliminato gli unici lista=[ 2 3 4 6 8 ]
Dopo lo swap lista=[ ] lista1=[ 2 3 4 6 8 ]
Dopo l'assegnamento lista=[ 2 3 4 6 8 ] lista1=[ 2 3 4 6 8 ]
Merge lista1 in lista; lista=[ 2 2 3 3 4 4 6 6 8 8 ] Lista1=[ ]
Lista dopo rimuovi 4.0 lista=[ 2 2 3 3 6 6 8 8 ]
dopo ins array lista1=[ 2 6 4 8 2 ]
Trovato nodo=0x26E408, *nodo+E=2.0
Trovato nodo=0x26DFB8, *nodo+E=2.0
Alla fine r=0 cr=0



Ian Collins

unread,
May 28, 2012, 5:51:33 AM5/28/12
to
On 05/28/12 09:26 PM, io_x wrote:
> "io_x"<a...@b.c.invalid> ha scritto nel messaggio
> news:4fc0f6c2$0$1390$4faf...@reader1.news.tin.it...
>>
>
>>> than possible i condider equivalent u32, u32* and void* and u8* and i8*...
>
> do you like the OOP version...
>
> /*
> #define uns unsigned

Is io_x a gibberish generating automaton?

--
Ian Collins

James Kuyper

unread,
May 28, 2012, 12:08:22 PM5/28/12
to
On 05/28/2012 05:51 AM, Ian Collins wrote:
> On 05/28/12 09:26 PM, io_x wrote:
...d
>> do you like the OOP version...
>>
>> /*
>> #define uns unsigned
>
> Is io_x a gibberish generating automaton?

If not, he's doing a good imitation of one.
--
James Kuyper

Rui Maciel

unread,
May 28, 2012, 2:29:31 PM5/28/12
to
Ian Collins wrote:

> Is io_x a gibberish generating automaton?

Maybe he is a sock puppet of Mark V Shaney.

http://en.wikipedia.org/wiki/Mark_V_Shaney


Rui Maciel

io_x

unread,
May 31, 2012, 4:44:04 AM5/31/12
to

"Rui Maciel" <rui.m...@gmail.com> ha scritto nel messaggio
news:jq0g67$kak$3...@speranza.aioe.org...
this below is an implementation of list of list...
yes stl it seems better
but in informatic never what it seems ... is

/* Test per Liste e array --------*/
/*
#define uns unsigned
#define u32 unsigned
#define u64 unsigned __int64
#define i32 int
#define u16 unsigned short
#define u8 unsigned char
#define i8 char
#define i16 short
#define long_long __int64
#define sdC __stdcall
#define ooo cout
#define S sizeof
#define MM Malloc_m
#define FF Free_m

#define F for
#define R return
#define W while
#define G goto

*/

i32 __stdcall pelm(u32 elm){R P("%u ", elm)<=0 ? -1 : 0; }

i32 List2Pu32(u32* list, u8* testo)
{u32 r;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=List2Nelem(list); if(r==-1) G vai;
if(testo){if(P("%s",testo)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1(list, pelm);
if(P("]" )<=0) R -1;
R r?-1:0;
}

i32 __stdcall pdouble(u8* elm)
{u32 cr=0;
GetSizeFast(elm); cr+=cf(); // controlla che venga da malloc
if(cr){P("Err"); R -1;}
R P("%.0f ", *(double*)elm)<=0 ? -1 : 0;
}


i32 List2Pdouble(u32* list, u8* msg)
{u32 r, cr=0;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=List2NelemA(list); if(r==-1) G vai;
if(msg)
{if( P("%s", msg)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1A(list, pdouble); cr+=(r!=0);
if(P("]" )<=0) R -1;
if(cr) G vai;
R r;
}

u8* DaiMemDouble(double a)
{double *r;
r=(double*)MM(S *r); if(r==0) R 0;
*r=a;
R (u8*)r;
}

// costruttore distruttore copia di double
u8* sdC dcst(void) {R (u8*)MM(S(double));}
u32 sdC ddst(u8* a) {R FF(a)?-1:0;}
u32 sdC dcpy(u8* d, u8* o){R MmrCpy(d, o, S(double))==0?-1:0;}

i32 cmpu32(u32 a, u32 b)
{ if(a> b) R 1;
else if(a==b) R 0;
else R -1;
}

i32 cmpadouble(u8* aa, u8* bb)
{double *a, *b;

if(aa==0||bb==0) R -3;
a=(double*)(aa); b=(double*)(bb);
// P("%.1f<>%.1f ", *a, *b);
if(*a> *b) R 1;
else if(*a==*b) R 0;
else R -1;
}

i32 __stdcall cmp4 (u32 elm){i32 r=elm; r-=4; R r; }

i32 __stdcall cmpd4(u8* elm)
{double *r;
if(elm==0) R -3;
r=(double*)elm;
if(*r==4.0) R 0;
R 1;
}

// costruttore distruttore copia di lista
u8* sdC lcst(void)
{u32 *a;
a=(u32*)MM(2*S(u32));
if(a==0) R 0;
a[0]=0; a[1]=0;
R (u8*) a;
}

u32 sdC ldst(u8* a)
{u32 r, cr;
if(a==0) R -1;
r=List2Free((u32*)a);
GetSizeFast(a); cr=cf(); // controlla che venga da malloc
if(cr==1) R -1;
R (FF(a)||r==-1)?-1:0;
}

u32 sdC lcpy(u8* d, u8* o)
{R List2AssegnaListaA((u32*)d, 0, 0,(u32*)o);}

int testList3(void)
{double m;
u32 lista[2]={0}, lista1[2]={0},
lista2[2]={0},i, j, r, cr, x, y, z, *pu;
u8 *pr;

cr=0; z=1;
// crea una lista di liste
r=List2CreA(lista, 2*S(u32), lcst, ldst, lcpy);
if(r==-1) R -1;
// crea una liste di double
r=List2CreA(lista1, S(double), dcst, ddst, dcpy);
if(r==-1) {ex: P("Error%u\n", z);
List2FreeA(lista); R -1;}
z=2;
// lista1 di double
m=1.0; r=List2PushHA(lista1, (u8*)&m); cr+=(r==-1);
m=2.0; r=List2PushHA(lista1, (u8*)&m); cr+=(r==-1);
m=4.0; r=List2PushTA(lista1, (u8*)&m); cr+=(r==-1);
m=3.0; r=List2PushTA(lista1, (u8*)&m); cr+=(r==-1);
// push una copia dinamica di tale lista
List2PushTA(lista, (u8*) lista1); cr+=(r==-1);
r=List2Free(lista1); cr+=(r==-1); // rimuove lista1
if(cr!=0) G ex;
z=3;
// lista1 di u32
r=List2PushH(lista1, 10); cr+=(r==-1);
r=List2PushH(lista1, 20); cr+=(r==-1);
r=List2PushT(lista1, 40); cr+=(r==-1);
r=List2PushT(lista1, 30); cr+=(r==-1);
if(cr!=0) G ex;
z=4;
// push copia dinamica di lista1 in lista
List2PushTA(lista, (u8*) lista1); cr+=(r==-1);
r=List2Free(lista1); cr+=(r==-1); // rimuove lista1
if(cr!=0) G ex;
z=5;
// print lista double
pr=0; // preleva la head
r=List2Next(lista, &pr); if(r==-1||r==1) G ex;
pu=(u32*)List2elmA(pr);
r=List2Pdouble(pu,"double lista1="); cr+=(r==-1); P("\n");
if(cr!=0) G ex;
// printdouble perchè sapevo che era una lista di double...
// conviene in questo metodo definire sempre liste di liste
// con liste dello stesso tipo per non sbagliare facilmente
z=6;
// print lista int
r=List2Next(lista, &pr); if(r==-1) G ex;
if(r==1) P("Elemento finale\n");
pu=(u32*)List2elmA(pr); // accede alla lista
r=List2Pu32(pu,"u32 lista1="); cr+=(r==-1); P("\n");
if(cr!=0) G ex;
z=7;
r=List2Free(lista); cr+=(r==-1);
if(cr!=0) G ex;
R 0;
}


double lista1=[ 2 1 4 3 ]
u32 lista1=[ 20 10 40 30 ]

-----------------------



io_x

unread,
Jun 2, 2012, 2:42:55 AM6/2/12
to

"io_x" <a...@b.c.invalid> ha scritto nel messaggio
news:4fc72e0d$0$1388$4faf...@reader1.news.tin.it.../*

my first C OO program...

/*
#define uns unsigned
#define u32 unsigned
#define u64 unsigned __int64
#define i32 int
#define u16 unsigned short
#define u8 unsigned char
#define i8 char
#define i16 short
#define long_long __int64
#define sdC __stdcall
#define ooo cout
#define S sizeof
#define MM Malloc_m
#define FF Free_m

#define F for
#define R return
#define W while
#define G goto
*/

i32 __stdcall pelm(u8* elm){R P("%u ", elm)<=0 ? -1 : 0; }

i32 List2Pu32(u32* list, u8* testo)
{u32 r;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=List2Nelem(list); if(r==-1) G vai;
if(testo){if(P("%s",testo)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1(list, pelm);
if(P("]" )<=0) R -1;
R r?-1:0;
}


i32 __stdcall pdouble(u8* elm)
{u32 cr=0;
GetSizeFast(elm); cr+=cf(); // controlla che venga da malloc
if(cr){P("Err"); R -1;}
R P("%.0f ", *(double*)elm)<=0 ? -1 : 0;
}


i32 List2Pdouble(u32* list, u8* msg)
{u32 r, cr=0;

if(list==0) {vai: P("[ERRORE LISTA]"); R -1; }
r=List2Nelem(list); if(r==-1) G vai;
if(msg)
{if( P("%s", msg)<=0) R -1;}
if(r==0) {R P("[ ]")<=0 ? -1: 0;}
if(P("[ ")<=0) R -1;
r=List2Applica1(list, pdouble); cr+=(r!=0);
if(P("]" )<=0) R -1;
if(cr) G vai;
R r;
}

u8* DaiMemDouble(double a)
{double *r;
r=(double*)MM(S *r); if(r==0) R 0;
*r=a;
R (u8*)r;
}

u8* sdC dcst(void) {R (u8*)MM(S(double));}
u32 sdC ddst(u8* a) {R FF(a)?-1:0;}
u32 sdC dcpy(u8* d, u8* o){R MmrCpy(d, o, S(double))==0?-1:0;}

i32 cmpu32(u8* a, u8* b)
{ if(a> b) R 1;
else if(a==b) R 0;
else R -1;
}

i32 cmpadouble(u8* aa, u8* bb)
{double *a, *b;

if(aa==0||bb==0) R -3;
a=(double*)(aa); b=(double*)(bb);
// P("%.1f<>%.1f ", *a, *b);
if(*a> *b) R 1;
else if(*a==*b) R 0;
else R -1;
}

i32 __stdcall cmp4 (u8* elm){i32 r=(i32)elm; r-=4; R r; }

i32 __stdcall cmpd4(u8* elm)
{double *r;
if(elm==0) R -3;
r=(double*)elm;
if(*r==4.0) R 0;
R 1;
}

u8* sdC lcst(void)
{u32 *a;
a=(u32*)MM(2*S(u32));
if(a==0) R 0;
a[0]=0; a[1]=0;
R (u8*) a;
}

u32 sdC ldst(u8* a)
{u32 r, cr;
if(a==0) R -1;
r=List2Free((u32*)a);
GetSizeFast(a); cr=cf(); // controlla che venga da malloc
if(cr==1) R -1;
R (FF(a)||r==-1)?-1:0;
}

u32 sdC lcpy(u8* d, u8* o)
{R List2AssegnaLista((u32*)d, 0, 0,(u32*)o);}

int testList3(void)
{double m;
u32 lista[2]={0}, lista1[2]={0},
i, j, r, cr, x, y, z, *pu;
u8 *pr;

cr=0; z=1;
// crea una lista di liste
r=List2Crea(lista, 2*S(u32), lcst, ldst, lcpy);
if(r==-1) R -1;
// crea una liste di double
r=List2Crea(lista1, S(double), dcst, ddst, dcpy);
if(r==-1) {ex: P("Error%u\n", z);
List2Free(lista); R -1;}
z=2;
// lista1 di double
m=1.0; r=List2PushH(lista1, (u8*)&m); cr+=(r==-1);
m=2.0; r=List2PushH(lista1, (u8*)&m); cr+=(r==-1);
m=4.0; r=List2PushT(lista1, (u8*)&m); cr+=(r==-1);
m=3.0; r=List2PushT(lista1, (u8*)&m); cr+=(r==-1);

List2PushT(lista, (u8*) lista1); cr+=(r==-1);
r=List2Free(lista1); cr+=(r==-1); // rimuove lista1
if(cr!=0) G ex;
z=3;
// lista1 di u32
r=List2PushH(lista1, (u8*)10); cr+=(r==-1);
r=List2PushH(lista1, (u8*)20); cr+=(r==-1);
r=List2PushT(lista1, (u8*)40); cr+=(r==-1);
r=List2PushT(lista1, (u8*)30); cr+=(r==-1);
if(cr!=0) G ex;
z=4;
// push lista1 in lista
List2PushT(lista, (u8*) lista1); cr+=(r==-1);
r=List2Free(lista1); cr+=(r==-1); // rimuove lista1
if(cr!=0) G ex;
z=5;
// print lista double
pr=0; // preleva la head
r=List2Next(lista, &pr); if(r==-1||r==1) G ex;
pu=(u32*)List2elm(pr);
r=List2Pdouble(pu,"double lista1="); cr+=(r==-1); P("\n");
if(cr!=0) G ex;
z=6;
// print lista int
r=List2Next(lista, &pr); if(r==-1) G ex;
if(r==1) P("Elemento finale\n");
pu=(u32*)List2elm(pr);

pete

unread,
Jun 2, 2012, 7:48:07 AM6/2/12
to
io_x wrote:
>
> "io_x" <a...@b.c.invalid> ha scritto nel messaggio
> news:4fc72e0d$0$1388$4faf...@reader1.news.tin.it.../*
>
> my first C OO program...

That's not a C program.

--
pete

Gordon Burditt

unread,
Sep 14, 2012, 4:50:10 PM9/14/12
to
> The fact that it has done so in the past is no good reason for
> continuing to do the same stupid thing in the present. Blind obedience
> to that sexist tradition ironically leaves English with no way to
> distinguish a reference exclusively to a male from a reference that
> includes either a male or a female.

In order to avoid unnecessary sexism or speciesism, use s/he/it,
which is, of course, pronounced "shit".

Ben Bacarisse

unread,
Sep 14, 2012, 5:51:43 PM9/14/12
to
You thought this putrid pearl amusing enough to reply to a four month
old message?

--
Ben.

James Kuyper

unread,
Sep 14, 2012, 8:50:47 PM9/14/12
to
On 09/14/2012 04:50 PM, Gordon Burditt wrote:
[Unatrributed text from a message that I wrote a couple of months ago.]

I've told you this before (2011-03-30, 2011-10-18, 2012-03-12, and
2012-03-14), but apparently I need to remind you again. Permission to
quote any part of any message I post, without proper attribution, is denied.
--
James Kuyper

Keith Thompson

unread,
Sep 14, 2012, 9:51:26 PM9/14/12
to
And Gordon, you could completely address all the concerns you say
you have with attribution lines simply by changing the content of
your attribution message to something like:

So-and-so <so.a...@example.com> appears to have written:

or

In an article attributed to So-and-so <so.a...@example.com> somebody wrote:

or some wording of your choice. It would neatly solve the problem
you claim to have and save you the effort of keeping track of who
has denied you permission to quote their words without attribution.
I can only assume that you have some other reason that you haven't
chosen to tell us about.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
0 new messages