R
Rick C. Hodgin
Kaz, I don't know about the history of C. Over time I've learned to use the
language and I have written a lot of code in it. I am currently working on a
large project written entirely in C. I understand most C code when I read it.
Much beyond a pointer to a pointer and my head starts to spin though.I don't purport to be an expert in C standards. Never have been. Never will
be. I have no interest in becoming an expert in that. I came here asking for
something specific and no one had a solution for me, just workarounds. That
was, until this solution was introduced:
char* list[] = { "jjj", (char[]){"kkk"}}.
The following solves the problem, and is highly portable. Moreover, it has
basically the same structure and should compile to the same object code; it
just doesn't have the source-level "syntactic sugar":
char el0[] = "jjj";
char el1[] = "kkk";
char *list[] = { list_elem1, list_elem1 };
That solution was discussed. It is workable, but it is unmanageable because
the element block in question in my particular case is about 100 lines and
will change from time to time.
You do not have an actual "problem" here; you're just looking for how to do
something using the minimal number of keystrokes.
Correct. I have had a working work-around the entire time I've been
discussing this.
Also note that you could just waste a few bytes and do this, which also
works in pretty much any C dialect:
char list[][128] = {
"everything",
"is mutable now"
};
That solution was discussed. It is also workable, but it was undesirable
for me as it's clunky, wasteful, and so on.
(This program isn't targetting tiny embedded systems where every byte
counts, is it? It's a code generation tool that runs on developer machines
and build servers. It runs for a few milliseconds and then terminates,
freeing all of its memory to the OS.)
Yes. It's entirely on principle I rejected it, not mechanics.
The number of keystrokes you've wasted in this newsgroup outweighs
any savings by now from the syntactic sugar.
I found the solution I wanted, and learned many things in the process.
It was positive.
The approach you're taking of mutating global strings is an poor design for
what you're doing, based on a poor choice of programming language.
Kaz, you don't know what I'm doing on this project. You don't know any of
the details of what I'm doing. You don't have any idea of the size, scope,
or any aspect of its design, history, or anything else.
In short: You are not equipped to render a verdict like that.
A high school kid working in, say, Lisp, Python, Ruby or Perl would
have the project done already.
My project is done. I had a solution before I came here. I had a solution
about two weeks before I came here. I originally discussed this subject on
comp.os.ms-windows.programmer.win32 asking specifically for a Visual C++
extension, and after much discussion someone there suggested I try here.
It's purely a mental exercise. Mechanically it was solved the very hour I
first discovered that the char* list[] = { "one", "two", "three" }; were all
read-only. I just wrote a work-around. But, I also wanted to find out a
better way.
Yeah, minor issue: can't actually use the solution in one of the development
environments you use, and have been mentioning from the start.
I didn't say "minor issue" ... I said "totally separate issue". I did find
what I was looking for. It's now a shortcoming in Microsoft's product that
it is not supported, not a shortcoming in C.
Love you, Kaz. Keep on keeping on.
Best regards,
Rick C. Hodgin