Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #160147 > unrolled thread
| Started by | Manfred <noname@add.invalid> |
|---|---|
| First post | 2021-04-17 19:12 +0200 |
| Last post | 2021-04-28 00:02 -0700 |
| Articles | 20 on this page of 89 — 20 participants |
Back to article view | Back to comp.lang.c
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-17 19:12 +0200
Re: No, C is not a simple language silas poulson <Silas8642@hotmail.co.uk> - 2021-04-17 18:33 -0700
Re: No, C is not a simple language Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-04-18 02:10 +0000
Re: No, C is not a simple language silas poulson <Silas8642@hotmail.co.uk> - 2021-04-17 22:35 -0700
Re: No, C is not a simple language Real Troll <real.troll@trolls.com> - 2021-04-18 17:00 +0100
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-18 21:52 +0200
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-18 16:46 +0000
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-18 20:30 +0200
Re: No, C is not a simple language Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-18 12:46 -0700
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-18 22:53 +0200
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-04-19 04:20 -0700
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-19 08:29 -0700
Re: No, C is not a simple language Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-04-19 13:21 -0700
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-19 18:03 -0400
Re: No, C is not a simple language Bart <bc@freeuk.com> - 2021-04-20 00:50 +0100
Re: No, C is not a simple language David Brown <david.brown@hesbynett.no> - 2021-04-20 08:32 +0200
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 07:17 -0400
Re: No, C is not a simple language David Brown <david.brown@hesbynett.no> - 2021-04-20 14:25 +0200
Re: No, C is not a simple language Bart <bc@freeuk.com> - 2021-04-20 14:09 +0100
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 10:19 -0400
Re: No, C is not a simple language James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-20 11:50 -0400
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 12:06 -0400
Re: No, C is not a simple language James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-04-20 19:13 -0400
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:29 -0700
Re: No, C is not a simple language David Brown <david.brown@hesbynett.no> - 2021-05-11 14:37 +0200
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:18 -0700
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:14 -0700
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-19 07:18 +0000
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-19 17:15 +0200
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 04:05 +0000
Re: No, C is not a simple language Manfred <noname@add.invalid> - 2021-04-20 18:27 +0200
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-20 16:41 +0000
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 19:44 +0200
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-20 11:04 -0700
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 20:23 +0200
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-20 12:22 -0700
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 19:37 +0000
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 18:30 +0000
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-20 20:47 +0200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:29 -0700
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-21 04:37 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-21 15:26 -0700
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-22 05:59 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 11:58 -0700
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-23 07:23 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 14:26 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 14:28 -0700
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-20 14:46 -0400
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 20:18 +0000
Re: No, C is not a simple language Tim Rentsch <tr.17687@z991.linuxsc.com> - 2021-05-11 05:31 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:19 -0700
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-20 20:29 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 13:39 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 14:29 -0700
Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-21 08:56 +1200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-20 14:07 -0700
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 12:10 +0200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:37 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:38 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 12:43 -0700
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-23 22:38 +0200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 13:44 -0700
Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-24 10:56 +1200
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-23 16:09 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:30 +0000
Re: No, C is not a simple language Ian Collins <ian-news@hotmail.com> - 2021-04-30 21:11 +1200
Re: No, C is not a simple language Kaz Kylheku <563-365-8930@kylheku.com> - 2021-04-24 03:51 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-24 12:48 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:24 +0000
Re: No, C is not a simple language jacobnavia <jacob@jacob.remcomp.fr> - 2021-04-26 21:24 +0200
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-27 07:26 +0000
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:27 +0000
Re: No, C is not a simple language "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2021-04-20 19:53 +0200
Re: No, C is not a simple language Thiago Adams <thiago.adams@gmail.com> - 2021-04-20 11:04 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 09:02 +0000
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 09:43 +0000
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-26 03:08 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 10:35 +0000
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-26 13:08 +0000
Re: No, C is not a simple language Richard Damon <Richard@Damon-Family.org> - 2021-04-26 09:30 -0400
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 14:22 +0000
Re: No, C is not a simple language scott@slp53.sl.home (Scott Lurndal) - 2021-04-26 18:57 +0000
Re: No, C is not a simple language Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-04-26 06:55 -0700
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-26 14:15 +0000
Re: No, C is not a simple language Juha Nieminen <nospam@thanks.invalid> - 2021-04-27 04:37 +0000
Re: No, C is not a simple language Robert Latest <boblatest@yahoo.com> - 2021-04-27 07:22 +0000
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-19 21:42 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-22 00:26 -0700
Re: No, C is not a simple language "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-04-28 00:02 -0700
Page 1 of 5 [1] 2 3 4 5 Next page →
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-17 19:12 +0200 |
| Subject | Re: No, C is not a simple language |
| Message-ID | <s5f4u8$1t7u$1@gioia.aioe.org> |
(cross-posting to comp.lang.c to let the heat fire up) On 4/17/2021 7:56 AM, Juha Nieminen wrote: > I know that this is probably going to piss off avid C programmers, > but I don't really care all that much. Excellent start [...] > > I myself happen to know both languages quite well, and in fact I > program in both languages as my profession, and I would say that > I am very knowledgeable and proficient in both languages and have > no trouble in developing in either one. I am of the strong opinion > that no, C is not a "simple" language, and that C++ makes so many > things so much simpler, easier and safer. > > I was reminded of this in a quite concrete manner recently when I was > trying to help a beginner programmer who had decided to try his hands > on C, and wanted to create a simple text editor, which would read a > text file, allow the user to edit the text in several ways, and to > save the file. > > It quite quickly turned very frustrating for *both* of us ... The first comment that comes to mind is that probably part of the frustration stems from your approach (no offense) to try and use in C a design that would be suitable for C++ instead. Despite their name, the two are quite different languages. The similarities are about their runtime footprint, not about how they are used. For example, at a first glance the design of string object is not that great for C. A common pattern that pops to the mind is to use opaque structs (see e.g. FILE*), and have something like: typedef struct string_t STRING; STRING* alloc_string(); // creates the empty string STRING* set_string(STRING* s, const char* value); void free_string(STRING* s); STRING* concat_string(STRING* s1, STRING* s2); ... This way there would be no ambiguity about how the STRING object has to be used. And yes, in C you have to do all yourself - C is a low level language, and it is meant for low level stuff. It is hardly the right tool for anything meant to interface with a human user - it is (still) great for system programming and back-end processing, IMO. As second, I agree with Jacob that a text editor is a simple tool, but it is not easy to make expecially for a beginner. [snip]
[toc] | [next] | [standalone]
| From | silas poulson <Silas8642@hotmail.co.uk> |
|---|---|
| Date | 2021-04-17 18:33 -0700 |
| Message-ID | <261cbfaa-e05c-4d8b-a5a1-9a4749495809n@googlegroups.com> |
| In reply to | #160147 |
On Saturday, 17 April 2021 at 18:12:52 UTC+1, Manfred wrote: > (cross-posting to comp.lang.c to let the heat fire up) > As second, I agree with Jacob that a text editor is a simple tool, but > it is not easy to make expecially for a beginner. For those wanting assistance, Kernighan and Plauger's *Software Tools* present a Pascal version of the venerable ED Silas
[toc] | [prev] | [next] | [standalone]
| From | Lew Pitcher <lew.pitcher@digitalfreehold.ca> |
|---|---|
| Date | 2021-04-18 02:10 +0000 |
| Message-ID | <s5g4fe$ue4$1@dont-email.me> |
| In reply to | #160176 |
On Sat, 17 Apr 2021 18:33:13 -0700, silas poulson wrote:
> On Saturday, 17 April 2021 at 18:12:52 UTC+1, Manfred wrote:
>> (cross-posting to comp.lang.c to let the heat fire up)
>
>> As second, I agree with Jacob that a text editor is a simple tool, but
>> it is not easy to make expecially for a beginner.
>
> For those wanting assistance, Kernighan and Plauger's *Software Tools*
> present a Pascal version
Only in /some/ editions. The 1976 edition in my bookcase presents all code
examples in RatFor ("Rational Fortran", a C-like language transpiled into
Fortran).
I believe that, as language fads came and went, K&P updated "Software Tools"
to reflect the (then) current "language-of-choice".
> of the venerable ED
>
> Silas
--
Lew Pitcher
"In Skills, We Trust"
[toc] | [prev] | [next] | [standalone]
| From | silas poulson <Silas8642@hotmail.co.uk> |
|---|---|
| Date | 2021-04-17 22:35 -0700 |
| Message-ID | <05c0ee66-9e1a-455c-8aa7-dbeb87351024n@googlegroups.com> |
| In reply to | #160181 |
On Sunday, 18 April 2021 at 03:11:06 UTC+1, Lew Pitcher wrote:
> examples in RatFor ("Rational Fortran", a C-like language transpiled into
> Fortran).
Indeed, forgot my Pascal version was the re-release.
> I believe that, as language fads came and went, K&P updated "Software Tools"
> to reflect the (then) current "language-of-choice".
Only once!
The Pascal rewrite lead to Kernighan's (in)famous
*Why Pascal is Not My Favorite Programming Language* commentary
Silas
[toc] | [prev] | [next] | [standalone]
| From | Real Troll <real.troll@trolls.com> |
|---|---|
| Date | 2021-04-18 17:00 +0100 |
| Message-ID | <s5hm2q$1o8n$1@gioia.aioe.org> |
| In reply to | #160176 |
On 18/04/2021 02:33, silas poulson wrote: > > For those wanting assistance, Kernighan and Plauger's *Software Tools* > present a Pascal version of the venerable ED > It's a silly suggestion from Silas (no pun intended!). We are in 2021 and people should try to use latest books. Technology has moved on and no one compiler is good in the 21st century and therefore archaic books are for academic research and not for serious programming work.
[toc] | [prev] | [next] | [standalone]
| From | jacobnavia <jacob@jacob.remcomp.fr> |
|---|---|
| Date | 2021-04-18 21:52 +0200 |
| Message-ID | <s5i2li$jgj$1@dont-email.me> |
| In reply to | #160190 |
Le 18/04/2021 à 18:00, Real Troll a écrit : > On 18/04/2021 02:33, silas poulson wrote: >> >> For those wanting assistance, Kernighan and Plauger's *Software Tools* >> present a Pascal version of the venerable ED >> > > It's a silly suggestion from Silas (no pun intended!). We are in 2021 > and people should try to use latest books. Technology has moved on and > no one compiler is good in the 21st century and therefore archaic books > are for academic research and not for serious programming work. > > Dear real troll You make honor to your pseudo. We are NOT speaking about real programming WORK but a project for a beginner. See the posts before this one,specially the first one where Mr Nieminen explains the context. In THAT context, the answer of Mr Silas is prefectly appropiate. ed is a project where you can begin honing your c skills.
[toc] | [prev] | [next] | [standalone]
| From | Juha Nieminen <nospam@thanks.invalid> |
|---|---|
| Date | 2021-04-18 16:46 +0000 |
| Message-ID | <s5hnpu$k19$1@gioia.aioe.org> |
| In reply to | #160147 |
In comp.lang.c++ Manfred <noname@add.invalid> wrote: > For example, at a first glance the design of string object is not that > great for C. > A common pattern that pops to the mind is to use opaque structs (see > e.g. FILE*), and have something like: > > typedef struct string_t STRING; > > STRING* alloc_string(); // creates the empty string > STRING* set_string(STRING* s, const char* value); > void free_string(STRING* s); > STRING* concat_string(STRING* s1, STRING* s2); > ... > > This way there would be no ambiguity about how the STRING object has to > be used. I see no practical difference between that and a String struct. The usage is pretty much the same, and all the same problems appear (such as assigning one string object/pointer to another requiring extra care to avoid destroying the string twice or accessing a destroyed string).
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-18 20:30 +0200 |
| Message-ID | <s5htsr$1jr9$1@gioia.aioe.org> |
| In reply to | #160192 |
On 4/18/2021 6:46 PM, Juha Nieminen wrote: > In comp.lang.c++ Manfred <noname@add.invalid> wrote: >> For example, at a first glance the design of string object is not that >> great for C. >> A common pattern that pops to the mind is to use opaque structs (see >> e.g. FILE*), and have something like: >> >> typedef struct string_t STRING; >> >> STRING* alloc_string(); // creates the empty string >> STRING* set_string(STRING* s, const char* value); >> void free_string(STRING* s); >> STRING* concat_string(STRING* s1, STRING* s2); >> ... >> >> This way there would be no ambiguity about how the STRING object has to >> be used. > > I see no practical difference between that and a String struct. The usage is > pretty much the same, and all the same problems appear (such as assigning > one string object/pointer to another requiring extra care to avoid destroying > the string twice or accessing a destroyed string). > If the struct is opaque, the compiler won't allow you to assign a STRING object to another, as a start. In fact it won't allow to perform /any/ operation on the object, except through the API that you define. You can still mess up with pointers, but if you want to use C, then you have to know better. This is nothing new, as I wrote the entire FILE* infrastructure works this way.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-04-18 12:46 -0700 |
| Message-ID | <878s5f1im9.fsf@nosuchdomain.example.com> |
| In reply to | #160198 |
Manfred <noname@add.invalid> writes:
> On 4/18/2021 6:46 PM, Juha Nieminen wrote:
>> In comp.lang.c++ Manfred <noname@add.invalid> wrote:
>>> For example, at a first glance the design of string object is not that
>>> great for C.
>>> A common pattern that pops to the mind is to use opaque structs (see
>>> e.g. FILE*), and have something like:
>>>
>>> typedef struct string_t STRING;
>>>
>>> STRING* alloc_string(); // creates the empty string
>>> STRING* set_string(STRING* s, const char* value);
>>> void free_string(STRING* s);
>>> STRING* concat_string(STRING* s1, STRING* s2);
>>> ...
>>>
>>> This way there would be no ambiguity about how the STRING object has to
>>> be used.
>>
>> I see no practical difference between that and a String struct. The usage is
>> pretty much the same, and all the same problems appear (such as assigning
>> one string object/pointer to another requiring extra care to avoid destroying
>> the string twice or accessing a destroyed string).
>>
>
> If the struct is opaque, the compiler won't allow you to assign a
> STRING object to another, as a start. In fact it won't allow to
> perform /any/ operation on the object, except through the API that you
> define.
>
> You can still mess up with pointers, but if you want to use C, then
> you have to know better.
>
> This is nothing new, as I wrote the entire FILE* infrastructure works
> this way.
Except that you *can* assign objects of type FILE (if you don't mind
undefined behavior). The FILE type is opaque in the sense that the
standard doesn't say what it looks like, but it has to be an object
type.
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Manfred <noname@add.invalid> |
|---|---|
| Date | 2021-04-18 22:53 +0200 |
| Message-ID | <s5i68f$1g9m$1@gioia.aioe.org> |
| In reply to | #160200 |
On 4/18/2021 9:46 PM, Keith Thompson wrote:
> Manfred <noname@add.invalid> writes:
>> On 4/18/2021 6:46 PM, Juha Nieminen wrote:
>>> In comp.lang.c++ Manfred <noname@add.invalid> wrote:
>>>> For example, at a first glance the design of string object is not that
>>>> great for C.
>>>> A common pattern that pops to the mind is to use opaque structs (see
>>>> e.g. FILE*), and have something like:
>>>>
>>>> typedef struct string_t STRING;
>>>>
>>>> STRING* alloc_string(); // creates the empty string
>>>> STRING* set_string(STRING* s, const char* value);
>>>> void free_string(STRING* s);
>>>> STRING* concat_string(STRING* s1, STRING* s2);
>>>> ...
>>>>
>>>> This way there would be no ambiguity about how the STRING object has to
>>>> be used.
>>>
>>> I see no practical difference between that and a String struct. The usage is
>>> pretty much the same, and all the same problems appear (such as assigning
>>> one string object/pointer to another requiring extra care to avoid destroying
>>> the string twice or accessing a destroyed string).
>>>
>>
>> If the struct is opaque, the compiler won't allow you to assign a
>> STRING object to another, as a start. In fact it won't allow to
>> perform /any/ operation on the object, except through the API that you
>> define.
>>
>> You can still mess up with pointers, but if you want to use C, then
>> you have to know better.
>>
>> This is nothing new, as I wrote the entire FILE* infrastructure works
>> this way.
>
> Except that you *can* assign objects of type FILE (if you don't mind
> undefined behavior). The FILE type is opaque in the sense that the
> standard doesn't say what it looks like, but it has to be an object
> type.
>
The relevant part was:
> typedef struct string_t STRING;
I am talking about opaque types, which are incomplete and as such you
can't use objects of their type.
As far as the standard is concerned FILE is an opaque type whose
definition might not be seen (and in fact is _not_ intended to be seen,
let alone used) by user code.
I think it is clear that the fact that in some implementations the
definition of FILE might percolate into user TUs is orthogonal to this
discussion.
$ cat opaque.c
typedef struct string_t STRING;
STRING* string_concat(STRING* s1, STRING* s2);
void string_free(STRING* s);
void foo(STRING* s1, STRING* s2)
{
STRING* s3 = string_concat(s1, s2);
string_free(s3);
}
void bar(STRING* s1, STRING* s2)
{
*s2 = *s1; // can't do that
}
$ cc -std=c11 -Wall -pedantic -c opaque.c
opaque.c: In function ‘bar’:
opaque.c:17:9: error: invalid use of incomplete typedef ‘STRING’ {aka
‘struct string_t’}
17 | *s2 = *s1;
| ^
opaque.c:17:7: error: invalid use of incomplete typedef ‘STRING’ {aka
‘struct string_t’}
17 | *s2 = *s1;
| ^
[toc] | [prev] | [next] | [standalone]
| From | Tim Rentsch <tr.17687@z991.linuxsc.com> |
|---|---|
| Date | 2021-04-19 04:20 -0700 |
| Message-ID | <86h7k2h66j.fsf@linuxsc.com> |
| In reply to | #160200 |
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes: > Manfred <noname@add.invalid> writes: >> [...] [discussion of opaque types using pointers to structs whose contents are not defined] >> This is nothing new, as I wrote the entire FILE* infrastructure >> works this way. > > Except that you *can* assign objects of type FILE (if you don't > mind undefined behavior). The FILE type is opaque in the sense > that the standard doesn't say what it looks like, but it has to be > an object type. It should be noted that the term "object type" acquired a new meaning in C11. Before C11, the C standard divides types into function types, object types, and incomplete types, so "object type" always meant a complete type and not an incomplete type. Starting in C11, the C standard divides types into function types and object types, with object types further divided into complete object types and incomplete object types. So although it is true that FILE is an object type, starting in C11 that doesn't mean it is necessarily a complete object type.
[toc] | [prev] | [next] | [standalone]
| From | Thiago Adams <thiago.adams@gmail.com> |
|---|---|
| Date | 2021-04-19 08:29 -0700 |
| Message-ID | <d1a7a5dd-b6f8-4af8-b6c9-6a454e5a960dn@googlegroups.com> |
| In reply to | #160219 |
On Monday, April 19, 2021 at 8:20:31 AM UTC-3, Tim Rentsch wrote: > Keith Thompson <Keith.S.T...@gmail.com> writes: > > > Manfred <non...@add.invalid> writes: > >> [...] > > [discussion of opaque types using pointers to structs whose contents > are not defined] > >> This is nothing new, as I wrote the entire FILE* infrastructure > >> works this way. > > > > Except that you *can* assign objects of type FILE (if you don't > > mind undefined behavior). The FILE type is opaque in the sense > > that the standard doesn't say what it looks like, but it has to be > > an object type. > It should be noted that the term "object type" acquired a new > meaning in C11. Before C11, the C standard divides types into > function types, object types, and incomplete types, so "object > type" always meant a complete type and not an incomplete type. > Starting in C11, the C standard divides types into function types > and object types, with object types further divided into complete > object types and incomplete object types. So although it is true > that FILE is an object type, starting in C11 that doesn't mean it > is necessarily a complete object type. Last week I receive a warning in clang complaining about converting void* to function pointer. Searching for this error I found a explanation that C99 or C11 I don't recall makes this distinction and this conversion is not guaranteed. The solution proposed on stack overflow was storing a dummy function pointer instead of void*, lets say void (PF)(void) and then cast this dummy function pointer to the final type. I decided just ignore the warning in my code. The justification was that void* could have different size than function pointers.
[toc] | [prev] | [next] | [standalone]
| From | Keith Thompson <Keith.S.Thompson+u@gmail.com> |
|---|---|
| Date | 2021-04-19 13:21 -0700 |
| Message-ID | <87tuo2yqiq.fsf@nosuchdomain.example.com> |
| In reply to | #160223 |
Thiago Adams <thiago.adams@gmail.com> writes:
> On Monday, April 19, 2021 at 8:20:31 AM UTC-3, Tim Rentsch wrote:
>> Keith Thompson <Keith.S.T...@gmail.com> writes:
>> > Manfred <non...@add.invalid> writes:
>> >> [...]
>>
>> [discussion of opaque types using pointers to structs whose contents
>> are not defined]
>> >> This is nothing new, as I wrote the entire FILE* infrastructure
>> >> works this way.
>> >
>> > Except that you *can* assign objects of type FILE (if you don't
>> > mind undefined behavior). The FILE type is opaque in the sense
>> > that the standard doesn't say what it looks like, but it has to be
>> > an object type.
>> It should be noted that the term "object type" acquired a new
>> meaning in C11. Before C11, the C standard divides types into
>> function types, object types, and incomplete types, so "object
>> type" always meant a complete type and not an incomplete type.
>> Starting in C11, the C standard divides types into function types
>> and object types, with object types further divided into complete
>> object types and incomplete object types. So although it is true
>> that FILE is an object type, starting in C11 that doesn't mean it
>> is necessarily a complete object type.
>
> Last week I receive a warning in clang complaining about
> converting void* to function pointer.
> Searching for this error I found a explanation that C99 or C11 I don't
> recall makes this distinction and this conversion is not guaranteed.
> The solution proposed on stack overflow was storing a dummy function
> pointer instead of void*, lets say void (PF)(void) and then cast this dummy
> function pointer to the final type.
> I decided just ignore the warning in my code.
> The justification was that void* could have different size than function pointers.
C does not define the behavior of converting between object pointer
types and function pointer types (except for the special case of a null
pointer constant). I believe that's been the case since C90.
The section of the standard on pointer conversions just omits any
mention of conversions between object pointer types and function pointer
types. The section on cast operators, however, doesn't say that such a
conversion is a constraint violation. I find this odd. (I think we had
a long and inconclusive discussion about this a while ago.)
It does allow conversions of function pointer types to and from
integers, and integers to and from object pointer types, but the results
are implementation-defined in most cases.
And yes, the rationale is that void* has to be big enough to hold any
object pointer value, but function pointers might be bigger than object
pointers (more precisely, they might not be convertible without loss of
information).
--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips Healthcare
void Void(void) { Void(); } /* The recursive call of the void */
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2021-04-19 18:03 -0400 |
| Message-ID | <i7nfI.33552$2A5.24325@fx45.iad> |
| In reply to | #160230 |
On 4/19/21 4:21 PM, Keith Thompson wrote: > Thiago Adams <thiago.adams@gmail.com> writes: >> Last week I receive a warning in clang complaining about >> converting void* to function pointer. >> Searching for this error I found a explanation that C99 or C11 I don't >> recall makes this distinction and this conversion is not guaranteed. >> The solution proposed on stack overflow was storing a dummy function >> pointer instead of void*, lets say void (PF)(void) and then cast this dummy >> function pointer to the final type. >> I decided just ignore the warning in my code. >> The justification was that void* could have different size than function pointers. > > C does not define the behavior of converting between object pointer > types and function pointer types (except for the special case of a null > pointer constant). I believe that's been the case since C90. > > The section of the standard on pointer conversions just omits any > mention of conversions between object pointer types and function pointer > types. The section on cast operators, however, doesn't say that such a > conversion is a constraint violation. I find this odd. (I think we had > a long and inconclusive discussion about this a while ago.) > > It does allow conversions of function pointer types to and from > integers, and integers to and from object pointer types, but the results > are implementation-defined in most cases. > > And yes, the rationale is that void* has to be big enough to hold any > object pointer value, but function pointers might be bigger than object > pointers (more precisely, they might not be convertible without loss of > information). > It isn't made a constraint violation because in many cases it does work and being able to do it is useful. It isn't defined to work, because on some machines it just can't be done (especially if they are different sizes or to different memory spaces like a Harvard Machine)
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2021-04-20 00:50 +0100 |
| Message-ID | <2HofI.289439$hcZe.74935@fx46.ams4> |
| In reply to | #160231 |
On 19/04/2021 23:03, Richard Damon wrote: > On 4/19/21 4:21 PM, Keith Thompson wrote: >> Thiago Adams <thiago.adams@gmail.com> writes: > >>> Last week I receive a warning in clang complaining about >>> converting void* to function pointer. >>> Searching for this error I found a explanation that C99 or C11 I don't >>> recall makes this distinction and this conversion is not guaranteed. >>> The solution proposed on stack overflow was storing a dummy function >>> pointer instead of void*, lets say void (PF)(void) and then cast this dummy >>> function pointer to the final type. >>> I decided just ignore the warning in my code. >>> The justification was that void* could have different size than function pointers. >> >> C does not define the behavior of converting between object pointer >> types and function pointer types (except for the special case of a null >> pointer constant). I believe that's been the case since C90. >> >> The section of the standard on pointer conversions just omits any >> mention of conversions between object pointer types and function pointer >> types. The section on cast operators, however, doesn't say that such a >> conversion is a constraint violation. I find this odd. (I think we had >> a long and inconclusive discussion about this a while ago.) >> >> It does allow conversions of function pointer types to and from >> integers, and integers to and from object pointer types, but the results >> are implementation-defined in most cases. >> >> And yes, the rationale is that void* has to be big enough to hold any >> object pointer value, but function pointers might be bigger than object >> pointers (more precisely, they might not be convertible without loss of >> information). >> > > It isn't made a constraint violation because in many cases it does work > and being able to do it is useful. > > It isn't defined to work, because on some machines it just can't be done > (especially if they are different sizes or to different memory spaces > like a Harvard Machine) > You can always make it work. On any machine where a raw function pointer is very different from an object pointer (say 256 bits vs, 64 bits), then a C compiler can implement such pointers via object pointers. In practice, for every actual function, there is an accompanying 256-bit value, in data memory, containing its address. A 'function pointer' as a C program will see it, is a 64-bit pointer to that 256-bit object. The compiler will take care of the double-dereference needed to call such a function. However cross-language libraries would need to cooperate on such a scheme to pass such function pointers via APIs.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-04-20 08:32 +0200 |
| Message-ID | <s5lshe$mb1$1@dont-email.me> |
| In reply to | #160232 |
On 20/04/2021 01:50, Bart wrote: > On 19/04/2021 23:03, Richard Damon wrote: >> On 4/19/21 4:21 PM, Keith Thompson wrote: >>> Thiago Adams <thiago.adams@gmail.com> writes: >> >>>> Last week I receive a warning in clang complaining about >>>> converting void* to function pointer. >>>> Searching for this error I found a explanation that C99 or C11 I don't >>>> recall makes this distinction and this conversion is not guaranteed. >>>> The solution proposed on stack overflow was storing a dummy function >>>> pointer instead of void*, lets say void (PF)(void) and then cast >>>> this dummy >>>> function pointer to the final type. >>>> I decided just ignore the warning in my code. >>>> The justification was that void* could have different size than >>>> function pointers. >>> >>> C does not define the behavior of converting between object pointer >>> types and function pointer types (except for the special case of a null >>> pointer constant). I believe that's been the case since C90. >>> >>> The section of the standard on pointer conversions just omits any >>> mention of conversions between object pointer types and function pointer >>> types. The section on cast operators, however, doesn't say that such a >>> conversion is a constraint violation. I find this odd. (I think we had >>> a long and inconclusive discussion about this a while ago.) >>> >>> It does allow conversions of function pointer types to and from >>> integers, and integers to and from object pointer types, but the results >>> are implementation-defined in most cases. >>> >>> And yes, the rationale is that void* has to be big enough to hold any >>> object pointer value, but function pointers might be bigger than object >>> pointers (more precisely, they might not be convertible without loss of >>> information). >>> >> >> It isn't made a constraint violation because in many cases it does work >> and being able to do it is useful. >> >> It isn't defined to work, because on some machines it just can't be done >> (especially if they are different sizes or to different memory spaces >> like a Harvard Machine) >> > > You can always make it work. On any machine where a raw function pointer > is very different from an object pointer (say 256 bits vs, 64 bits), > then a C compiler can implement such pointers via object pointers. > > In practice, for every actual function, there is an accompanying 256-bit > value, in data memory, containing its address. A 'function pointer' as a > C program will see it, is a 64-bit pointer to that 256-bit object. > > The compiler will take care of the double-dereference needed to call > such a function. > > However cross-language libraries would need to cooperate on such a > scheme to pass such function pointers via APIs. Such schemes are possible, and sometimes used in practice. (They have been used on the AVR - my usual go-to choice for a somewhat awkward architecture.) But I've also seen microcontrollers where function pointers are bigger than data pointers. Cooperation between languages or tools /always/ requires a common ABI - there is no special case here.
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2021-04-20 07:17 -0400 |
| Message-ID | <HLyfI.38396$2A5.844@fx45.iad> |
| In reply to | #160232 |
On 4/19/21 7:50 PM, Bart wrote: > On 19/04/2021 23:03, Richard Damon wrote: >> On 4/19/21 4:21 PM, Keith Thompson wrote: >>> Thiago Adams <thiago.adams@gmail.com> writes: >> >>>> Last week I receive a warning in clang complaining about >>>> converting void* to function pointer. >>>> Searching for this error I found a explanation that C99 or C11 I don't >>>> recall makes this distinction and this conversion is not guaranteed. >>>> The solution proposed on stack overflow was storing a dummy function >>>> pointer instead of void*, lets say void (PF)(void) and then cast >>>> this dummy >>>> function pointer to the final type. >>>> I decided just ignore the warning in my code. >>>> The justification was that void* could have different size than >>>> function pointers. >>> >>> C does not define the behavior of converting between object pointer >>> types and function pointer types (except for the special case of a null >>> pointer constant). I believe that's been the case since C90. >>> >>> The section of the standard on pointer conversions just omits any >>> mention of conversions between object pointer types and function pointer >>> types. The section on cast operators, however, doesn't say that such a >>> conversion is a constraint violation. I find this odd. (I think we had >>> a long and inconclusive discussion about this a while ago.) >>> >>> It does allow conversions of function pointer types to and from >>> integers, and integers to and from object pointer types, but the results >>> are implementation-defined in most cases. >>> >>> And yes, the rationale is that void* has to be big enough to hold any >>> object pointer value, but function pointers might be bigger than object >>> pointers (more precisely, they might not be convertible without loss of >>> information). >>> >> >> It isn't made a constraint violation because in many cases it does work >> and being able to do it is useful. >> >> It isn't defined to work, because on some machines it just can't be done >> (especially if they are different sizes or to different memory spaces >> like a Harvard Machine) >> > > You can always make it work. On any machine where a raw function pointer > is very different from an object pointer (say 256 bits vs, 64 bits), > then a C compiler can implement such pointers via object pointers. > > In practice, for every actual function, there is an accompanying 256-bit > value, in data memory, containing its address. A 'function pointer' as a > C program will see it, is a 64-bit pointer to that 256-bit object. > > The compiler will take care of the double-dereference needed to call > such a function. > > However cross-language libraries would need to cooperate on such a > scheme to pass such function pointers via APIs. Yes, you can make it work at a cost, perhaps heavy cost, and C tries not to make implementation do that sort of heavy cost. Also, on some machines, like those with a Harvard Architecture, using a data pointer can NEVER get you the contents at the function pointer, as you need to use different instructions to access the memory contents in instruction space than in data space. And the word width might even be different too.
[toc] | [prev] | [next] | [standalone]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Date | 2021-04-20 14:25 +0200 |
| Message-ID | <s5mh74$l3$1@dont-email.me> |
| In reply to | #160237 |
On 20/04/2021 13:17, Richard Damon wrote: > On 4/19/21 7:50 PM, Bart wrote: >> On 19/04/2021 23:03, Richard Damon wrote: >>> On 4/19/21 4:21 PM, Keith Thompson wrote: >>>> Thiago Adams <thiago.adams@gmail.com> writes: >>> >>>>> Last week I receive a warning in clang complaining about >>>>> converting void* to function pointer. >>>>> Searching for this error I found a explanation that C99 or C11 I don't >>>>> recall makes this distinction and this conversion is not guaranteed. >>>>> The solution proposed on stack overflow was storing a dummy function >>>>> pointer instead of void*, lets say void (PF)(void) and then cast >>>>> this dummy >>>>> function pointer to the final type. >>>>> I decided just ignore the warning in my code. >>>>> The justification was that void* could have different size than >>>>> function pointers. >>>> >>>> C does not define the behavior of converting between object pointer >>>> types and function pointer types (except for the special case of a null >>>> pointer constant). I believe that's been the case since C90. >>>> >>>> The section of the standard on pointer conversions just omits any >>>> mention of conversions between object pointer types and function pointer >>>> types. The section on cast operators, however, doesn't say that such a >>>> conversion is a constraint violation. I find this odd. (I think we had >>>> a long and inconclusive discussion about this a while ago.) >>>> >>>> It does allow conversions of function pointer types to and from >>>> integers, and integers to and from object pointer types, but the results >>>> are implementation-defined in most cases. >>>> >>>> And yes, the rationale is that void* has to be big enough to hold any >>>> object pointer value, but function pointers might be bigger than object >>>> pointers (more precisely, they might not be convertible without loss of >>>> information). >>>> >>> >>> It isn't made a constraint violation because in many cases it does work >>> and being able to do it is useful. >>> >>> It isn't defined to work, because on some machines it just can't be done >>> (especially if they are different sizes or to different memory spaces >>> like a Harvard Machine) >>> >> >> You can always make it work. On any machine where a raw function pointer >> is very different from an object pointer (say 256 bits vs, 64 bits), >> then a C compiler can implement such pointers via object pointers. >> >> In practice, for every actual function, there is an accompanying 256-bit >> value, in data memory, containing its address. A 'function pointer' as a >> C program will see it, is a 64-bit pointer to that 256-bit object. >> >> The compiler will take care of the double-dereference needed to call >> such a function. >> >> However cross-language libraries would need to cooperate on such a >> scheme to pass such function pointers via APIs. > > Yes, you can make it work at a cost, perhaps heavy cost, and C tries not > to make implementation do that sort of heavy cost. > > Also, on some machines, like those with a Harvard Architecture, using a > data pointer can NEVER get you the contents at the function pointer, as > you need to use different instructions to access the memory contents in > instruction space than in data space. And the word width might even be > different too. > The way this is typically done (at least as I have seen it) is that when you take the address of a function that needs a long address (perhaps even a bank switch), the compiler puts a "far-jump real_foo" instruction at a low flash addresses (or unbanked memory) and uses that as the address of the function "foo". That way your main code can call or jump to "foo" using a short address, while the real code lies elsewhere. The overhead is then just one extra branch instruction. (Well, sometimes it is more if the architecture has far-call and far-return instructions.)
[toc] | [prev] | [next] | [standalone]
| From | Bart <bc@freeuk.com> |
|---|---|
| Date | 2021-04-20 14:09 +0100 |
| Message-ID | <ooAfI.170722$i669.139473@fx02.ams4> |
| In reply to | #160237 |
On 20/04/2021 12:17, Richard Damon wrote:
> On 4/19/21 7:50 PM, Bart wrote:
>> You can always make it work. On any machine where a raw function pointer
>> is very different from an object pointer (say 256 bits vs, 64 bits),
>> then a C compiler can implement such pointers via object pointers.
>>
>> In practice, for every actual function, there is an accompanying 256-bit
>> value, in data memory, containing its address. A 'function pointer' as a
>> C program will see it, is a 64-bit pointer to that 256-bit object.
>>
>> The compiler will take care of the double-dereference needed to call
>> such a function.
>>
>> However cross-language libraries would need to cooperate on such a
>> scheme to pass such function pointers via APIs.
>
> Yes, you can make it work at a cost, perhaps heavy cost, and C tries not
> to make implementation do that sort of heavy cost.
>
> Also, on some machines, like those with a Harvard Architecture, using a
> data pointer can NEVER get you the contents at the function pointer, as
> you need to use different instructions to access the memory contents in
> instruction space than in data space. And the word width might even be
> different too.
>
Can C use function pointers on such architectures at all? In so, it can
work like this:
#include <stdio.h>
void (*F)(int,int); // points to instruction memory
void (**G)(int,int) = &F; // points to data memory
int main(void) {
F(10,20);
(*G)(10,20);
void* p;
p=F;
F=p;
p=G;
G=p;
}
F is a regular function pointer. G is an object pointer with an extra
level of indirection to the same function as F points to.
The assignments between p and F can generate warnings about ISO C
forbidding such conversions, even when you use casts.
But those between p and G are fine.
The proposal would be for the compiler to transparently implement
function pointers like G in my example rather than F. That means being
able to drop, in the source code, the extra * and & associated with G
(the compiler will add them).
> a data pointer can NEVER get you the contents at the function pointer
We're not trying to read the memory that the function pointer points to,
just execute it via a call.
Now, there might be a problem if you can't load an address from data
memory, which is the address of instruction memory. Well, obviously you
can, but I mean using it as an instruction memory.
For example, if there are separate sets of registers than can be loaded
from different kinds of memory; you can't move data between them; and
you can only call a function indirectly from the special instruction
registers.
The answer then is to quickly move on to a saner architecture. However,
since on virtually all actual architectures, a workaround as I outlined
should be possible, then I think it was unnecessary for ISO C to ban
outright conversions between object and function pointers. At least,
they should have been implementation-defined.
(I'm currently working on a new interpreter where a function pointer
points neither into data, nor into instructions (the byte-code
sequence), but is a reference into a symbol table.
Calling the function involves picking up the 'address' of the function
(pointer to the entry-point within the bytecode), from the symbol table
entry. But here the function 'pointer' can also pick up the name and
other info about the function.)
[toc] | [prev] | [next] | [standalone]
| From | Richard Damon <Richard@Damon-Family.org> |
|---|---|
| Date | 2021-04-20 10:19 -0400 |
| Message-ID | <ppBfI.20959$wd1.11495@fx41.iad> |
| In reply to | #160239 |
On 4/20/21 9:09 AM, Bart wrote:
> On 20/04/2021 12:17, Richard Damon wrote:
>> On 4/19/21 7:50 PM, Bart wrote:
>
>>> You can always make it work. On any machine where a raw function pointer
>>> is very different from an object pointer (say 256 bits vs, 64 bits),
>>> then a C compiler can implement such pointers via object pointers.
>>>
>>> In practice, for every actual function, there is an accompanying 256-bit
>>> value, in data memory, containing its address. A 'function pointer' as a
>>> C program will see it, is a 64-bit pointer to that 256-bit object.
>>>
>>> The compiler will take care of the double-dereference needed to call
>>> such a function.
>>>
>>> However cross-language libraries would need to cooperate on such a
>>> scheme to pass such function pointers via APIs.
>>
>> Yes, you can make it work at a cost, perhaps heavy cost, and C tries not
>> to make implementation do that sort of heavy cost.
>>
>> Also, on some machines, like those with a Harvard Architecture, using a
>> data pointer can NEVER get you the contents at the function pointer, as
>> you need to use different instructions to access the memory contents in
>> instruction space than in data space. And the word width might even be
>> different too.
>>
>
> Can C use function pointers on such architectures at all? In so, it can
> work like this:
Yes, Function pointers just are different sizes that the object pointer.
>
> #include <stdio.h>
>
> void (*F)(int,int); // points to instruction memory
> void (**G)(int,int) = &F; // points to data memory
>
> int main(void) {
>
> F(10,20);
> (*G)(10,20);
>
> void* p;
>
> p=F;
> F=p;
> p=G;
> G=p;
> }
>
> F is a regular function pointer. G is an object pointer with an extra
> level of indirection to the same function as F points to.
>
> The assignments between p and F can generate warnings about ISO C
> forbidding such conversions, even when you use casts.
Yes, because a void* object pointer may not have the capacity to store a
function pointer.
>
> But those between p and G are fine.
>
> The proposal would be for the compiler to transparently implement
> function pointers like G in my example rather than F. That means being
> able to drop, in the source code, the extra * and & associated with G
> (the compiler will add them).
Yes, to make function pointer to data pointer 'work' you may need to
create a thunk for every function that has its address taken. That is a
lot of work, and may require a smart linker to avoid overloading with
duplicates.
>
>> a data pointer can NEVER get you the contents at the function pointer
>
> We're not trying to read the memory that the function pointer points to,
> just execute it via a call.
>
Yes, but some may assume it will.
>
> Now, there might be a problem if you can't load an address from data
> memory, which is the address of instruction memory. Well, obviously you
> can, but I mean using it as an instruction memory.
>
> For example, if there are separate sets of registers than can be loaded
> from different kinds of memory; you can't move data between them; and
> you can only call a function indirectly from the special instruction
> registers.
>
> The answer then is to quickly move on to a saner architecture. However,
> since on virtually all actual architectures, a workaround as I outlined
> should be possible, then I think it was unnecessary for ISO C to ban
> outright conversions between object and function pointers. At least,
> they should have been implementation-defined.
>
It isn't that the work around can't work, it is that the standard does
not require that all such architecture go to that effort.
I suspect that one key reason is that when C was being developed, there
was little need to enforce this behavior on machines where it didn't
just work. It has NEVER been to goal of the standard to make it possible
to write all programs as strictly conforming programs.
>
> (I'm currently working on a new interpreter where a function pointer
> points neither into data, nor into instructions (the byte-code
> sequence), but is a reference into a symbol table.
>
> Calling the function involves picking up the 'address' of the function
> (pointer to the entry-point within the bytecode), from the symbol table
> entry. But here the function 'pointer' can also pick up the name and
> other info about the function.)
[toc] | [prev] | [next] | [standalone]
Page 1 of 5 [1] 2 3 4 5 Next page →
Back to top | Article view | comp.lang.c
csiph-web