[flac-dev] Are pointers to FLAC__int32 and int interchangeable?

Erik de Castro Lopo mle+la at mega-nerd.com
Wed Oct 7 14:06:08 PDT 2015


lvqcl wrote:

> Is it Ok to pass FLAC__int32* in a function that expects int* ?

Well FLAC__int32 is just a 32 bit integer and on all the platforms/
architecures/compilers that FLAC supports FLAC__int32 and int are
the same.

As for pointers, all pointers are the same until you try an increment
them. If you have some type, lets call it sometype_t, and a pointer to
types of sometype_t :

       sometype_t * ptr = 0 ;

and you then increment it using
   
       ptr ++ ;

The next address that the pointer points to is calculated using:

       ptr = (sometype_t *) ((char*) ptr) + 1) ;

where incrementing a char* pointer increases the address by 1.


> (the same question for FLAC__uint32* and unsigned*)

Very similar.

Personally I think the FLAC__xxxx stuff should go, to be replaced with
C standard int32_t, uint32_t, int16_t etc, at least for internal code.
I am slowly doing that when I touch code.

I don't think this should be done at the API level without an API
version bump and I don't think that is currently worth it.

HTH,
Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/


More information about the flac-dev mailing list