[Openal-devel] OpenAL Spec Observations
Eric Lengyel
lengyel at terathon.com
Thu Feb 26 07:27:17 PST 2004
Hi --
Declaring the pointer itself const (in addition to declaring what it
points to const) isn't actually a good thing. The value of the pointer
is copied during a function call and essentially becomes a local
variable for the called function. The function can change it in any
way that it wants (for instance, to advance to the next entry in an
array) without affecting the value of the pointer in the calling scope.
Same goes for any integral parameters. To the calling function, the
extra const is meaningless -- it only applies to the mutability of the
variable in the called function's scope, which is none of the
application's business.
> bool IsOpenALExtensionsPresent(const char* const pName)
> {
> return
> bool(alIsExtensionPresent(reinterpret_cast<ALubyte*>(pName));
> }
That won't compile because you cast away constness.
-- Eric
On Feb 26, 2004, at 3:11 AM, Carlos Abril wrote:
> Just a little note:
>
> You should notice that a parameter of type:
> - const type* pName means that the function can't change the contents
> pointed by pName (is constant) but can change the value of pName.
> - const type* const pName means that the function can't change the
> value
> of pName and can't change the contents pointed by pName.
>
> So, to be consistent with const-correct C++ code, the
> declarations/definitions of the functions that are not going to change
> the
> contents of the values pointed by the parameter should be const type*
> const.
>
> For example:
> ALvoid alGetFloatv( ALenum param, ALfloat* data );
> should be
> ALvoid alGetFloatv(const ALenum param, ALfloat* const data );
> Because the content pointed by data are going to be changed.
>
> and
> ALboolean alIsExtensionPresent(ALubyte* fname);
> Should be
> ALboolean alIsExtensionPresent(const ALubyte* cosnt fname);
>
>
> Because if you have something in your code like:
> bool IsOpenALExtensionPresent(const ALubyte* const pName)
> {
> return bool(alIsExtensionPresent(pName));
> }
> You need to have it declared this way.
>
> Anyway, it is something that I don't find important as it is always
> something that you have to do when working with C libraries (for
> example
> OpenGL). It is also true that you probably are not going to use the AL
> types
> and your function will look like:
>
> bool IsOpenALExtensionsPresent(const char* const pName)
> {
> return
> bool(alIsExtensionPresent(reinterpret_cast<ALubyte*>(pName));
> }
>
> Hope this helps.
>
> Carlos.
>
>
> -----Mensaje original-----
> De: openal-devel-admin at opensource.creative.com
> [mailto:openal-devel-admin at opensource.creative.com] En nombre de Garin
> Hiebert
> Enviado el: martes, 24 de febrero de 2004 23:29
> Para: OpenAL
> Asunto: Re: [Openal-devel] OpenAL Spec Observations
>
> I am finally really truly about to make the minor changes on the Mac
> and Windows code so that all the implementations will be using the
> exact same headers... If there are no objections, I'd like to also
> integrate a few of Eric's suggestions at the same time:
>
>> 1) Many of the OpenAL functions that take a "pointer to something" as
>> a parameter should be taking a "pointer to const something" instead.
>> Otherwise, calls to these functions do not compile under const-correct
>> C++ code. The following are the affected functions with their
>> parameter lists updated. Making this change will be 100% transparent
>> to all existing code since a "pointer to something" can always be
>> implicitly converted to a "pointer to const something".
>>
>> ALboolean alIsExtensionPresent( const ALubyte* fname );
>> ALvoid* alGetProcAddress( const ALubyte* fname );
>> ALenum alGetEnumValue( const ALubyte* ename );
>> ALvoid alListenerfv( ALenum param, const ALfloat* values );
>> ALvoid alDeleteSources( ALsizei n, const ALuint* sources );
>> ALvoid alSourcePlayv( ALsizei n, const ALuint *sources );
>> ALvoid alSourcePausev( ALsizei n, const ALuint *sources );
>> ALvoid alSourceStopv( ALsizei n, const ALuint *sources );
>> ALvoid alSourceRewindv( ALsizei n, const ALuint *sources );
>> ALvoid alDeleteBuffers( ALsizei n, const ALuint* buffers );
>> ALvoid alBufferData( ALuint buffer, ALenum format,
>> const ALvoid* data, ALsizei size, ALsizei freq );
>> ALvoid alSourceQueueBuffers( ALuint source, ALsizei n, const ALuint*
>> buffers );
>> ALvoid alSourceUnqueueBuffers( ALuint source, ALsizei n, const ALuint*
>> buffers );
>
> This seems rational to me... Would it cause problems for anyone?
>
>> 10) (Just an observation) The alSourcePausev and alSourceRewindv
>> functions are missing from the AL_NO_PROTOTYPES section of the al.h
>> header file.
>
> Seems like an easy oversight to fix -- I'll plan on it.
>
> Garin
>
>
> _______________________________________________
> openal-devel mailing list
> openal-devel at opensource.creative.com
> http://opensource.creative.com/mailman/listinfo/openal-devel
>
> _______________________________________________
> openal-devel mailing list
> openal-devel at opensource.creative.com
> http://opensource.creative.com/mailman/listinfo/openal-devel
>
More information about the Openal-devel
mailing list