:: Re: [DNG] Making sense of C pointer…
Forside
Slet denne besked
Besvar denne besked
Skribent: KatolaZ
Dato:  
Til: Edward Bartolo
CC: dng
Emne: Re: [DNG] Making sense of C pointer syntax.
On Mon, Mar 28, 2016 at 09:55:08PM +0200, Edward Bartolo wrote:
> Hi,
>
> Thanks for dedicating some of your time to answer me. I used:
>
> void change_value(void** ptr)
>
> Because I wanted to enable myself to allocate memory for the pointer
> inside the function, therefore I needed a pointer to a pointer of type
> void. Void allows such a function to handle different data types in
> which case an ordinal typed parameter may be used to allow a switch
> statement within the function to handle the different data types. I
> used such a construct in Delphi Pascal in the past, and consider it a
> powerful feature that can have its uses. This is why I am anxious to
> comprehend the why behind pointer to pointer use.
>


Allocating memory for a generic variable into a function is seldom of
any use, since you need to specify how much memory (number of bytes)
your function should allocate anyway. Although it is still possible to
code such a function, I think it is in general a bad idea. Why don't
you use malloc directly for this purpose?

Producing good-quality and maintanable software is also about
providing clean interfaces to the user, and by "interface" I mean
function signatures, which should be self-explanatory and clear. If I
can get almost anything as a result value of a function call, then
that function is likely to become a can of worms...

My2Cents

KatolaZ

--
[ Enzo Nicosia aka KatolaZ --- GLUG Catania -- Freaknet Medialab ]
[ me [at] katolaz.homeunix.net -- http://katolaz.homeunix.net -- ]
[ GNU/Linux User:#325780/ICQ UIN: #258332181/GPG key ID 0B5F062F ]
[ Fingerprint: 8E59 D6AA 445E FDB4 A153 3D5A 5F20 B3AE 0B5F 062F ]