KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Use defensive programming when hiding warnings
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: August 12, 2024

Specific compiler warnings can be hidden by inserting above the target lines of code a formatted comment with the warning number. For example, the “Pointer in COPY ARRAY” warning can be hidden like this:

C_POINTER($1)
ARRAY TEXT($fieldname_at; 0)

//%W-518.1
COPY ARRAY($1->; $fieldname_at)

However, hiding warnings can lead to problems in the future, so the issue should be handled accordingly before the warning is hidden. For instance, in the above example, if the pointer does not happen to be pointing to a text array in production, it can cause a problem when something fails due to wrong types. To avoid this, use ASSERT statements to throw an error like this:

//%W-518.1
ASSERT(Type($1->)=Text array; "$1 should be a pointer to text array.")
COPY ARRAY($1->; $fieldname_at)

Remember to also have an ON ERR CALL handler installed to catch the error and log it.