0

I recently read this sentence:

Do not declare this callback function with a void return type and cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread.

and wasn't sure if it was ambiguous or not. Which of these are correct interpretations:

  1. do not declare this callback function with a void return type
  2. do not cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread
  3. do cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread

Edit: I found some example code, seems like (1) and (3) is the intended interpretation.

1
  • It is ambiguous, and I wouldn't be too sure how to interpret it. If the intended interpretation is (1) and (3), I would use "instead" to clarify.
    – jocap
    Aug 31 '15 at 22:55
1

I believe the intent is (1) and (3). If (1) and (2) were intended, the more normal way to express it would be with or, not and.

Do not declare this callback function with a void return type or cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread.

I don't know if there's a logical reason for it, but not usually distributes over an or conjunction, but not over and and conjunction (except in cases where the conjunction refers to a well known combination, e.g. don't drink and drive).

1
  • That is the conclusion you'd reach using the rules of English alone, however, it's not right.
    – Ben Voigt
    May 4 '17 at 0:21
0

Do not declare this callback function with a void return type and cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread.

The problem is that what the sentence says and what the author meant may be different. Without the technical knowledge I would interpret it to mean,

Do not declare this callback function with a void return type and [do not] cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread.

If you want it to mean what you seem to be indicating then a different form of words would be necessary, e.g.

Do not declare this callback function with a void return type [but instead] cast the function pointer to LPTHREAD_START_ROUTINE when creating the thread.

I think you have to investigate further in a technical sense to be certain.

0
Let A = "declare this callback function with a void return type"
Let B = "cast the function pointer to LPTHREAD_START_ROUTINE"

The question concerns the scope of the "not," that is, whether the author means ¬A∧B or ¬(A∧B)

Grammar rules aren't dispositive here. You have to know what the terms mean.

  • A function is a named sequence of coding instructions that may or may not return a value usable in a program. When the programmer defines the function, he states (or declares) what type of value the function returns.

  • A function that doesn't return a usable value is said to be void or have a void return type.

  • A function may be invoked directly by using its name or by storing its name in a variable called a function pointer that is referenced by other functions. A function invoked by the latter method is called "a callback function."

  • Program values, including those returned by functions, may have their types changed by a programming facility called "casting." That is a value of one type may be changed to or "cast" to another type.

The warning here is that if you define a callback function to be void (i.e., it returns no usable value), do not try to change that fact by trying to convert its function pointer to a usable value.

In other words do not do A and B together.

0

This particular case isn't a grammar problem, you need subject-matter knowledge to analyze it.

  1. The LPTHREAD_START_ROUTINE data type is defined as pointing to a function which returns DWORD - Reference
  2. A function pointer stored by taking the address of a function returning void can only be passed to a library function accepting a LPTHREAD_START_PROCEDURE if a cast is used. - applying the International Standard for the C Programming Language, ISO/IEC 9899 rule on conversion of function arguments to parameter types

Therefore, the need for the cast is created by the incorrect return type. The two items mentioned in this instruction are not separated. Because there's a causal effect, not all combinations need to be considered.

The actual meaning of the sentence is:

Declare this callback function with a DWORD return type and then the function pointer will already be LPTHREAD_START_ROUTINE; you will not need a cast.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.