Zero terminated strings

S

spinoza1111

spinoza1111said:



I doubt that very much. I suppose it's possible, but I doubt it very,
very much indeed.

Translation: you've been painting a picture of my competence at
variance with the facts for ten years and you're going to wind up in a
court of law with witnesses who will attest to this truth.
Again, I doubt that very much. It's not, strictly speaking,
impossible, but it's far more likely that the compiler was behaving
quite properly but that you misunderstood it.

So tell me how was Nash to test overflow? Remember that I'd already
written a compiler and had encountered the problem of calculation at
compile time, and that I've written about this in a book that has
ranked in the top ten compiler books on Amazon.

You're headed for a libel suit. UK law is much stricter than American.
Lawsuits take time but they do happen to people, and my attorney and I
have an incredible amount of hard copy in your case. Do you really
want to lose your house, Richard?

You know, in 1994 I interviewed a group at DePaul University that was
using data systems to build the United Nations' case against Radovan
Karadzic, Ratko Mladic and Slobodan Milosevic for war crimes. Those
clowns assumed that "plausible deniability" and the chain of command
would hide their tracks although they'd supplied the heavy weapons of
the Yugoslavian army to the Bosnian Serbs, who laughed at women and
children they killed in Sarajevo.

The result was that these men were brought to account, if many years
later, and it may be thus with you. I am more articulate and better
educated than you and will defeat you in a UK court.

You have had a few sad and futile jobs with banks and insurance
companies, perhaps assisting in creating the UK bank collapses in 2008
with your incompetence. In the growing intervals of unemployment, you
have padded your resume by pretending to be a computer consultant as
if rural Britain needs another computer consultant as opposed to
policemen, teachers, and chicken sexers. Indeed, the fact that you are
always here attests to the probability that most of the time, you are
unemployed, and your wife is bringing in the steady paycheck.

This may be why you with such rancor go after people who've kept up
with changes in technology and accomplished things, people like
Schildt, Navia and Bemer. Your dominance of this ng proves to you that
you're a man. But you're not.
I don't think I've ever encountered any other person who actually
feels obliged to claim that they have social skills.

Most of the time this phrase is used in the negative register to prove
that a competent programmer who's been defraud of his production and
time doesn't deserve fairness and decency. Here it means that I was
probably asked to help Nash for the same reason my supervisor gave me
when she asked me to mentor Princeton HS hackers, that I was a good
mentor in sensitive areas. I surprised her because unlike nearly all
male American programmers, I wasn't an inarticulate, insensitive,
brutal little homophobic thug.

But all this aside, you're a little unemployed creep who whenever he
hears of another person's successes must destroy them.
 
C

Chris M. Thomasson

Translation: you've been painting a picture of my competence at
variance with the facts for ten years and you're going to wind up in a
court of law with witnesses who will attest to this truth.
[...]

Did you used to get beat up a lot in school?
 
E

electricdelta

I have a problem with all existing C programs that are buggy because of
a badly designed data structure Mr Pitcher is that clear to you?

Bugs are introduced due to erroneous assumptions about data and data
structures (such as null-terminated strings) and not because of the
data structures themselves. While null-terminated strings are error-
prone, it is perfectly possible to use them safely (and efficiently, I
might add) without much mental effort.
 
F

Flash Gordon

Gareth said:
Flash Gordon said:
struct string
{
unsigned len; /* possibly size_t rather than unsigned */
char str[];
}

How do you pass these on the stack as arguments to a function?

How are you going to pass a 10MB string on the stack anyway? If your
string might be large you should pass a pointer to it, otherwise I would
have to check the C99 standard to see if it allows passing it. Of
course, the standard could be updated to allow passing it as the last
parameter is such strings were being added to the standard.
Can I have an array of such struct strings?
No.

Wouldn't I have to use struct string pointers everywhere?

No, only in some places. The other alternative suggested has other
problems, especially when passing as a parameter. The suggestion I was
responding to was...

struct string
{
unsigned len;
char *str;
}

Pass that as a parameter to a function. The function modifies the string
and that modification is visible to the caller (because Cs pass by value
does not do a "deep" copy, i.e. the pointer in the copy will point to
the original string data), EXCEPT for changes to the length. So imagine
you have a string replace function...

void str_replace(string str; string search; string replace)
{
/* search str for all instances of search and replace them with
replace */
}

Call it with a replace string of different length to the search string
and you could get all sorts of problems which you don't with my suggestion.

Without radically changing the language it is a difficult problem to
solve. Jacob wants to use operator overloading and possibly other things
to deal with the issues. Paul Hiesh (sorry, I'm sure I've spelled that
wrong) has decided on another method using (I believe) only standard C,
but probably imposing restrictions on what you can do.
 
S

spinoza1111

spinoza1111said:



If that is true, it is a tragedy. But it is unlikely to be true.


Yes, you mentioned that many, many times, as if you'd done something
amazing. But apparently he was using int in a program he'd written,
but the int wasn't big enough, so you suggested long int, or possibly
unsigned long int - or something along those lines, anyway. End of
help. Gosh gee whizz.



That looks like an exaggeration to me.


Like a padded cell, right?


Ah, you've got Visual Basic working on mainframes now, have you?


Presumably you use C Sharp for professionally freezing and crashing
your system?

Can't be done inside managed code, and that's a good thing. Grow up.
 
S

spinoza1111

Gareth said:
struct string
{
  unsigned len; /* possibly size_t rather than unsigned */
  char str[];
}
How do you pass these on the stack as arguments to a function?

How are you going to pass a 10MB string on the stack anyway? If your

Duh...isn't char str[] == char *str, and doesn't that mean that
stacking that struct would be a trivial operation, involving maybe 8
bytes of data? Or did that famous Standard mung that equivalence too?
 
M

Moi

Gareth said:
Flash Gordon <[email protected]> writes:
struct string
{
  unsigned len; /* possibly size_t rather than unsigned */ char
  str[];
}
How do you pass these on the stack as arguments to a function?

How are you going to pass a 10MB string on the stack anyway? If your

Duh...isn't char str[] == char *str, and doesn't that mean that stacking
that struct would be a trivial operation, involving maybe 8 bytes of
data? Or did that famous Standard mung that equivalence too?


OMG
Case closed.
Next!

AvK
 
S

spinoza1111

Gareth Owen wrote:
struct string
{
  unsigned len; /* possibly size_t rather than unsigned */ char
  str[];
}
How do you pass these on the stack as arguments to a function?
How are you going to pass a 10MB string on the stack anyway? If your
Duh...isn't char str[] == char *str, and doesn't that mean that stacking
that struct would be a trivial operation, involving maybe 8 bytes of
data? Or did that famous Standard mung that equivalence too?

OMG
Case closed.
Next!

Perhaps it isn't anymore: perhaps it never was. I do recall that these
were alternative ways of expressing an array.

I stopped using C because like Fortran and Cobol, it was (and is) an
artifact about which little sensible or intelligent could be said, and
it generated authoritarian folklore. So fill me in.

I certainly don't believe that the above would stack the array. I
believe it would stack a pointer to the array.

I'm not here to learn an outdated and buggy language, especially not
from you clowns. I am here to get rid of Heathfield, who makes
intelligent and humane discussion on comp.programming. But if I have
to relearn C to do so, I will. I will get Navia's compiler reinstalled
on my system if I must.
 
S

spinoza1111

Translation: you've been painting a picture of my competence at
variance with the facts for ten years and you're going to wind up in a
court of law with witnesses who will attest to this truth.

[...]

Did you used to get beat up a lot in school?- Hide quoted text -

No. Did you?

When I was an undersized freshman at St Viator High School in
Arlington Heights in 1964, an upperclassman and varsity football
player pushed my heavy stack of books on the floor. I challenged him
to a fight although I knew I would lose. After school, we squared
away...and he said that he was sorry, because I was half his size.

Thereafter, I had NO trouble with bullying because I'd been willing to
go the distance with that guy, even though I wore black armbands and
antiwar buttons to school where most of the students were pro-war.

As such, it appalls me to see chronological grown-ups bully people
here because unlike me they never could admit to themselves that they
were bullied in school, and are forever trying to purge these memories
by finding another person who is "really" the mark and weakling they
still feel themselves to be.
 
C

Chris M. Thomasson

spinoza1111said:
On Aug 1, 5:53 pm, Richard Heathfield <[email protected]>
wrote:
spinoza1111said:

You see, I did as you recommend years and years ago. I taught C
at Princeton
If that is true, it is a tragedy. But it is unlikely to be true.
It's true.
I doubt that very much. I suppose it's possible, but I doubt it
very,
very much indeed.
Translation: you've been painting a picture of my competence at
variance with the facts for ten years and you're going to wind up in a
court of law with witnesses who will attest to this truth.

[...]

Did you used to get beat up a lot in school?- Hide quoted text -
No. Did you?

Na. I am a friendly guy, and had lots of friends in school. I was just
wondering if you got beat up a lot because you come across as a hard-core
major as%hole. Usually, as%holes get the shi% beat out of them every now and
then. I am glad that did not happen to you.

[...]
 
B

bartc

Flash Gordon said:
Gareth said:
That depends. It's probably true for long strings. If your string
implementation looks roughly like

struct string
{
unsigned len;
char * str;
}

then for short strings, looking up the length could easily cause a
cache miss -- or even a page fault -- depending on memory access
pattern and string accesses require an extra level of indirection.
NULL terminated strings have guaranteed memory locality.

A more likely structure would be...

struct string
{
unsigned len; /* possibly size_t rather than unsigned */
char str[];
}

So the length is guaranteed to be a few bytes before the start of the
character data. So memory locality should not be a problem unless your
pages are very short indeed!

If you have lots of short strings (say you are trying to load a massive
dictionary in to memory, one string per work) the memory overhead of the
length could become more significant.

Then you use a short length of one byte, and you don't need the terminator
so the overheads are the same. Or length could be variable. If access is
indirect (via functions or operator extensions), then the string type can do
anything it likes.

If the strings are allocated individually, then those overheads per-string
will probably outweigh the length ones.
 
M

Moi

Duh...isn't char str[] == char *str, and doesn't that mean that
stacking that struct would be a trivial operation, involving maybe 8
bytes of data? Or did that famous Standard mung that equivalence too?

OMG
Case closed.
Next!

Perhaps it isn't anymore: perhaps it never was. I do recall that these
were alternative ways of expressing an array.

I stopped using C because like Fortran and Cobol, it was (and is) an
artifact about which little sensible or intelligent could be said, and
it generated authoritarian folklore. So fill me in.

Hint: sizeof. Hint 2: lvalue.

I certainly don't believe that the above would stack the array. I
believe it would stack a pointer to the array.

How could recursion ever work if each invocation of the funtion would
actually share the same "local" variables ?
I'm not here to learn an outdated and buggy language, especially not
from you clowns. I am here to get rid of Heathfield, who makes

Then don't post here.
intelligent and humane discussion on comp.programming. But if I have to
relearn C to do so, I will. I will get Navia's compiler reinstalled on
my system if I must.

You can get plenty of help from this n.g.
If you are really willing to learn.

HTH,
AvK
 
M

Moi

Flash Gordon said:
Gareth said:
strcat is a MUCH faster operation if you do NOT seek the terminating
zero.

That depends. It's probably true for long strings. If your string
implementation looks roughly like

struct string
{
unsigned len;
char * str;
}

then for short strings, looking up the length could easily cause a
cache miss -- or even a page fault -- depending on memory access
pattern and string accesses require an extra level of indirection.
NULL terminated strings have guaranteed memory locality.

A more likely structure would be...

struct string
{
unsigned len; /* possibly size_t rather than unsigned */ char str[];
}

So the length is guaranteed to be a few bytes before the start of the
character data. So memory locality should not be a problem unless your
pages are very short indeed!

If you have lots of short strings (say you are trying to load a massive
dictionary in to memory, one string per work) the memory overhead of
the length could become more significant.

Then you use a short length of one byte, and you don't need the
terminator so the overheads are the same. Or length could be variable.
If access is indirect (via functions or operator extensions), then the
string type can do anything it likes.

If the strings are allocated individually, then those overheads
per-string will probably outweigh the length ones.

An alternative would be to misuse utf-8 encoding to store the length.
This would keep the alignment to 'char' and still allow a string length
of up to 16K, (IIRC).

AvK
 
F

Flash Gordon

Moi said:
Flash Gordon said:
Gareth Owen wrote:

strcat is a MUCH faster operation if you do NOT seek the terminating
zero.
That depends. It's probably true for long strings. If your string
implementation looks roughly like

struct string
{
unsigned len;
char * str;
}

then for short strings, looking up the length could easily cause a
cache miss -- or even a page fault -- depending on memory access
pattern and string accesses require an extra level of indirection.
NULL terminated strings have guaranteed memory locality.
A more likely structure would be...

struct string
{
unsigned len; /* possibly size_t rather than unsigned */ char str[];
}

So the length is guaranteed to be a few bytes before the start of the
character data. So memory locality should not be a problem unless your
pages are very short indeed!

If you have lots of short strings (say you are trying to load a massive
dictionary in to memory, one string per work) the memory overhead of
the length could become more significant.
Then you use a short length of one byte, and you don't need the
terminator so the overheads are the same.

Thus limiting the length of the string quite severely, or requiring
multiple different string types.

Adding complexity, if you mean what I think you mean.

The complexity is still there, and unless you do all the changes to the
language required to make strings a first class type (which I think
would be large changes) the complexity will show itself in various places.

There are other ways to do it. Allocate one block in which you store
multiple strings separated by the null termination. Then you have only
one allocation overhead for however many strings you have.
An alternative would be to misuse utf-8 encoding to store the length.
This would keep the alignment to 'char' and still allow a string length
of up to 16K, (IIRC).

That kind of scheme is, I think, what bartc meant by "or length could be
variable". However, it does add complexity. It may well be valuable and
worth while complexity, but it is still there.

As the old saying goes, "There ain't no such thing as a free lunch".

When I'm doing major string handling I prefer to use languages other
than C which have better string handling and in which strings are a
first class type. Making C such a language would, in my opinion, be a
big change.
 
J

James Kuyper

electricdelta said:
Bugs are introduced due to erroneous assumptions about data and data
structures (such as null-terminated strings) and not because of the
data structures themselves.

Some data structures are so hard to use right that their poor design
must be held at least partially responsible for the failures that occur
when they are misunderstood. To believe otherwise is to relieve all
designers of data structures from any responsibility for the quality of
their work. However, I would not agree with jacob's assessment that null
are that hard to use correctly.
 
S

spinoza1111

He does not want help.


He isn't.

It would be better in my opinion if everyone just ignored him.

Aw, now Flash, you sure? What if your namesake had tried to ignore
Ming The Merciless?
 
S

spinoza1111

This is the second attack on zero in this newsgroup within two weeks.

Hi Malcolm. I do not care for the feelings of artifacts. What concerns
me is the systematic trashing of people in this ng, coupled with
machine worship. And NUL termination was a mistake.
 
S

spinoza1111

Ad hominem is the assertion that an argument is wrong because of the person
who is making it.

eg
   The Duke of Edinburgh thinks that single mothers should not get benefits,
but he lives off the State himself..
   The Pope thinks that condom use is immoral, but what does he know because
he is celibate?
    Kids think it is necessary to have the latest trainers.
    Islam is a black man's religion.

It is not the same an an insult. Most insults are not ad hominem arguments.

This clear explanation gets five stars.
 
S

spinoza1111

And you could say the language encourages bad data structures. Most programs
operate on what are really nested arrays, though the nesting can go quite
deep. Eg user has a list of animations, which consist of list of keyframes,
which consist of lists of vertices, which consist of a list of 3 x,y,z
co-ordiantes.
However there is no one, obvious way to code this in C. In practise you will
find that several ways are used of defining the lists, usually for no real
reason.

You've just invented object oriented code. I salute you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top