[fpc-pascal] Optional param modifier

Ryan Joseph ryan at thealchemistguild.com
Sat Apr 13 19:04:40 CEST 2019



> On Apr 13, 2019, at 12:40 PM, Benito van der Zander <benito at benibela.de> wrote:
> 
> Hi,
> 
> the parameter is already optional without any modifier, since you can always pass nil for it.

Sorry I must be doing a bad job explaining this and the naming of “optional” seems to be confusing since it conflicts with existing terms. The param/return is indeed optional but there’s no way to know that as the programmer.

Ok, here’s a historic real work example which is all too common:

  int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);

Can you pass null for attr? Well you need to read the man page and read through multiple paragraphs to find out "If attr is NULL, then the thread is created with default attributes.” See: http://man7.org/linux/man-pages/man3/pthread_create.3.html

Clearing up this situation with a tiny little syntax is all I propose. Make that fact known in code and force pthread_create to check if attr is nil before dereferencing it. 

> 
> Perhaps there could be the opposite modifier, so the function cannot be called with nil. Like

Interesting idea but I’d have to think about it more to know if this is a real problem I’ve ever experienced.

Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list