Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Ian Collins Newsgroups: comp.lang.c Subject: Re: usecases of void foo(char **b) {} Date: Sat, 5 Nov 2016 16:34:32 +1300 Lines: 43 Message-ID: References: <87mvhjo3jw.fsf@bsb.me.uk> <3a09f5ec-d4f7-40fa-9855-b5c3f02ce4e9@googlegroups.com> <87ziljks6k.fsf@bsb.me.uk> <2199a2dd-d844-4f8d-bfe0-6a7c2854277b@googlegroups.com> <87twbqlsin.fsf@bsb.me.uk> <87oa1yljof.fsf@bsb.me.uk> <87ins5k15t.fsf@bsb.me.uk> <87bmxxm6zs.fsf@gmail.com> <871syrijhw.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net qQR33f3Ruw8zuABedJ5SXQ8U0jZ9uGMcbEamOzUPVX6Wk+3djz Cancel-Lock: sha1:DfLVO/+Q6cKgnjaJy9I9vu1oWqQ= User-Agent: Mozilla/5.0 (X11; SunOS i86pc; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 In-Reply-To: Xref: csiph.com comp.lang.c:95822 On 11/ 5/16 02:32 PM, BartC wrote: > On 04/11/2016 23:16, Ian Collins wrote: >> On 11/ 5/16 09:30 AM, BartC wrote: >>> On 04/11/2016 19:55, asetofsymbols@gmail.com wrote: >>>> Bart wrote: >>>> Instead I not understand >>>> >>>>> typedef int (*Matrix)[columns]; >>>> >>>> What I like is: >>>> int *matrx=malloc (size); >>>> All linear even if it is >>>> one nxm matrix... >>> >>> Well, the matrix being passed here /is/ linear, as the original is >>> int[][] so they must match. >>> >>> What's happening is the same as when you use int* when the original is >>> int[]. >>> >>> Matrix points to one row of the original, of width . Which is >>> another puzzling thing as 'columns' is a variable. Did you even know >>> that that C allows variables when declaring array dimensions, and in a >>> typedef? This doesn't quite fit the pattern of VLA as the only thing >>> allocated locally is a pointer. (And what happens if 'columns' was to >>> change after Matrix is declared?) >>> >>> The obvious (to me) way of declaring Matrix would be as >>> int(*)[][columns]. The original is int[][]; this is a pointer to that. >> >> If you find this stuff to complicated in C, why don't you use C++ where >> the types you want either already exist, or can be built? > > What I'm talking about already exists in C. But people are using every > excuse not to use it. My point was if you don't like the ambiguity of arrays and pointers, in C++ if you want to pass an array, you pass an array type. If you want to pass a matrix, you pass a matrix type. In C++ you hardly ever have to pass a naked pointer. -- Ian