Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #140354
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Distributing C as headers. |
| Date | 2019-01-28 13:23 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <q2ms8d$cd5$1@dont-email.me> (permalink) |
| References | (16 earlier) <OTr3E.154256$592.32298@fx16.am4> <87bm41vb3k.fsf@bsb.me.uk> <10t3E.125278$9A2.93679@fx09.am4> <8736pdv80w.fsf@bsb.me.uk> <m2y375c9it.fsf@despina.home> |
On 28/01/2019 12:21, Pascal J. Bourguignon wrote: > Ben Bacarisse <ben.usenet@bsb.me.uk> writes: > >> Bart <bc@freeuk.com> writes: >> >>> On 28/01/2019 01:12, Ben Bacarisse wrote: >>>> Bart <bc@freeuk.com> writes: >>>> >>>>> On 28/01/2019 00:06, Bart wrote: >>>>>> On 27/01/2019 23:51, Pascal J. Bourguignon wrote: >>>>> >>>>>>> In C, you need a lot more information to be able to use the header. >>>>>>> In Pascal, you have all the information you need: >>>>>>> >>>>>>> var >>>>>>> dst:string; >>>>>>> begin >>>>>>> string_copy(dst,'Hello World'); >>>>>>> end; >>>>>>> >>>>>>> will work without crashing. >>>>>> >>>>>> What would string_copy(dst, dst) do? What is the capacity of dst? >>>>>> (Last time I used Pascal, strings had to have a fixed length.) >>>>> >>>>> I couldn't compile your Pascal code. Do you have a real, complete >>>>> example that will run? I have Free Pascal Compiler. >>>> >>>> This is a runable example, though I have no idea if it illustrates >>>> whatever point was being made: >>>> >>>> program copystring (output); >>>> procedure string_copy(var dst : string; src : string); >>>> begin >>>> dst := src >>>> end; >>>> var dst : string; >>>> begin >>>> string_copy(dst, 'Hello World'); >>>> write(dst) >>>> end. >>> >>> Thanks. I think the point was that you couldn't make a Pascal program crash, as the interfaces are more robust. However if I modify your example to: >>> >>> program copystring (output); >>> procedure string_copy(var dst : string; src : string); >>> begin >>> string_copy(dst,src) >>> end; >>> var dst : string; >>> begin >>> string_copy(dst, 'Hello World'); >>> write(dst) >>> end. >>> >>> then run via FPC it gives me: >>> >>> Runtime error 202 at $0040142E >>> $0040142E >>> $00401441 >>> $00401441 >>> $00401441 >>> $00401441 >>> $00401441 >>> $00401441 >>> $00401441 >>> $00401441 >>> $00401441 >>> >>> (at a wild guess, it's run out of stack). I would say that it has >>> crashed. >> >> I went and looked. James was talking about pointers so a more direct >> example might be this: >> >> program copystring (output); >> procedure string_copy(var dst : string; src : string); >> begin >> dst := src >> end; >> var dp : ^string; >> begin >> string_copy(dp^, 'Hello World'); >> write(dp^) >> end. > > Part of the point that you could avoid using pointer in non-C > programming languages. There are constructs such as passing arguments > by reference, or using opaque objects (such as string) instead of bare > pointers to characters with some missing attribute such as allocated > size or length that must be passed on the side, which is propice to > errors, and ultimately crashes. > > When you are passing references in other languages, the underlying implementation is still passing around pointers. You can do the same in C - wrap your pointers inside structs, use access functions or macros. The difference is that in C you need to make these yourself and you don't get as neat syntax. Since you talk about "C programming languages" plural, are you including C++ ? In C++ you can pass by reference, make classes such as string, etc. - and you can get a result that is both faster and safer than with Pascal.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Distributing C as headers. Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-01-25 07:23 -0800
Re: Distributing C as headers. Thiago Adams <thiago.adams@gmail.com> - 2019-01-25 07:31 -0800
Re: Distributing C as headers. Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-01-25 07:33 -0800
Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-25 15:42 +0000
Re: Distributing C as headers. gazelle@shell.xmission.com (Kenny McCormack) - 2019-01-25 17:40 +0000
Re: Distributing C as headers. Thiago Adams <thiago.adams@gmail.com> - 2019-01-25 09:59 -0800
Re: Distributing C as headers. Thiago Adams <thiago.adams@gmail.com> - 2019-01-25 10:01 -0800
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-25 22:17 +0100
Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-25 21:33 +0000
Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-25 18:07 +0000
Re: Distributing C as headers. gazelle@shell.xmission.com (Kenny McCormack) - 2019-01-25 18:46 +0000
Re: Distributing C as headers. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-01-25 19:43 -0700
Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-26 08:13 +0000
Re: Distributing C as headers. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-01-26 13:39 -0700
Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-26 21:00 +0000
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:29 +0100
Re: Distributing C as headers. nobody@example.org (Scott) - 2019-01-27 04:56 +0000
Re: Distributing C as headers. Dan Purgert <dan@djph.net> - 2019-01-27 11:36 +0000
Re: Distributing C as headers. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-02-25 12:26 -0800
Re: Distributing C as headers. "Jason C. McDonald" <indeliblebluepen@gmail.com> - 2019-02-28 19:52 +0000
Re: Distributing C as headers. Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2019-02-28 15:04 -0500
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-02-28 21:40 +0100
Re: Distributing C as headers. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-02-28 13:57 -0800
Re: Distributing C as headers. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-01-27 13:33 +0000
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-27 15:06 +0100
Re: Distributing C as headers. luser droog <luser.droog@gmail.com> - 2019-01-26 13:01 -0800
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:30 +0100
Re: Distributing C as headers. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-02-02 09:27 +0000
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:23 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-26 13:39 -0800
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:47 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-26 14:33 -0800
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 23:37 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-26 15:09 -0800
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-27 15:11 +0100
Re: Distributing C as headers. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-01-27 16:12 -0500
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 00:51 +0100
Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 00:06 +0000
Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 00:18 +0000
Re: Distributing C as headers. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-01-28 01:12 +0000
Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 01:35 +0000
Re: Distributing C as headers. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-01-28 02:19 +0000
Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 10:40 +0000
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:22 +0100
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:21 +0100
Re: Distributing C as headers. Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-01-28 04:03 -0800
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:23 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-28 11:16 -0800
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 21:08 +0100
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 01:19 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-27 16:59 -0800
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-27 16:33 -0800
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 01:35 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-27 17:20 -0800
Re: Distributing C as headers. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-01-27 22:50 -0500
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 06:52 +0100
Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 10:55 +0000
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:26 +0100
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:27 +0100
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:26 +0100
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 14:03 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-28 11:12 -0800
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:25 +0100
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:33 +0100
Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-28 11:20 -0800
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 21:11 +0100
Re: Distributing C as headers. scott@slp53.sl.home (Scott Lurndal) - 2019-01-28 21:12 +0000
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 23:06 +0100
Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-27 15:02 +0100
Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-25 17:51 +0100
Re: Distributing C as headers. fir <profesor.fir@gmail.com> - 2019-01-25 14:28 -0800
csiph-web