ly common REFACTOR cast warnings
diff --git a/src/context.c b/src/context.c
index 6a1703e..912f56d 100644
--- a/src/context.c
+++ b/src/context.c
@@ -721,7 +721,7 @@
                 ext = &mod->compiled->exts[u];
                 LY_ARRAY_FOR(ext->substmts, v) {
                     if (ext->substmts[v].stmt & LY_STMT_DATA_NODE_MASK) {
-                        LY_LIST_FOR(*(struct lysc_node **)ext->substmts[v].storage, root) {
+                        LY_LIST_FOR(*VOIDPTR2_C(ext->substmts[v].storage), root) {
                             lysc_tree_dfs_full(root, lysc_node_clear_priv_dfs_cb, NULL);
                         }
                     }
diff --git a/src/ly_common.h b/src/ly_common.h
index ec0d3ea..8dc32d7 100644
--- a/src/ly_common.h
+++ b/src/ly_common.h
@@ -61,6 +61,9 @@
 #define GETMACRO6(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
 #define GETMACRO7(_1, _2, _3, _4, _5, _6, _7, NAME, ...) NAME
 
+#define VOIDPTR_C(var) ((void *)(uintptr_t)(var))
+#define VOIDPTR2_C(var) ((void **)(uintptr_t)(var))
+
 /******************************************************************************
  * Logger
  *****************************************************************************/
diff --git a/src/parser_common.c b/src/parser_common.c
index f33b9a7..290e3a5 100644
--- a/src/parser_common.c
+++ b/src/parser_common.c
@@ -3587,7 +3587,7 @@
         LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, (void **)&pnode, NULL), cleanup);
 
         /* usually is a linked-list of all the parsed schema nodes */
-        pnodes_p = (struct lysp_node **)substmt->storage;
+        pnodes_p = VOIDPTR_C(substmt->storage);
         while (*pnodes_p) {
             pnodes_p = &(*pnodes_p)->next;
         }
@@ -3615,7 +3615,7 @@
     case LY_STMT_TYPEDEF:
     case LY_STMT_UNIQUE:
         /* parse, sized array */
-        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, (void **)substmt->storage, NULL), cleanup);
+        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
         break;
 
     case LY_STMT_ARGUMENT:
@@ -3650,50 +3650,50 @@
     case LY_STMT_YANG_VERSION:
     case LY_STMT_YIN_ELEMENT:
         /* single item */
-        if (*(void **)substmt->storage) {
+        if (*VOIDPTR2_C(substmt->storage)) {
             LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
             rc = LY_EVALID;
             goto cleanup;
         }
 
         /* parse */
-        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, (void **)substmt->storage, NULL), cleanup);
+        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
         break;
 
     case LY_STMT_CONFIG:
         /* single item */
-        if ((*(uint16_t *)substmt->storage) & LYS_CONFIG_MASK) {
+        if ((*(uint16_t *)VOIDPTR2_C(substmt->storage)) & LYS_CONFIG_MASK) {
             LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
             rc = LY_EVALID;
             goto cleanup;
         }
 
         /* parse */
-        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, (void **)substmt->storage, NULL), cleanup);
+        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
         break;
 
     case LY_STMT_ORDERED_BY:
         /* single item */
-        if ((*(uint16_t *)substmt->storage) & LYS_ORDBY_MASK) {
+        if ((*(uint16_t *)VOIDPTR2_C(substmt->storage)) & LYS_ORDBY_MASK) {
             LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
             rc = LY_EVALID;
             goto cleanup;
         }
 
         /* parse */
-        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, (void **)substmt->storage, NULL), cleanup);
+        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
         break;
 
     case LY_STMT_STATUS:
         /* single item */
-        if ((*(uint16_t *)substmt->storage) & LYS_STATUS_MASK) {
+        if ((*(uint16_t *)VOIDPTR2_C(substmt->storage)) & LYS_STATUS_MASK) {
             LOGVAL(PARSER_CTX(pctx), LY_VCODE_DUPSTMT, stmt->stmt);
             rc = LY_EVALID;
             goto cleanup;
         }
 
         /* parse */
-        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, (void **)substmt->storage, NULL), cleanup);
+        LY_CHECK_GOTO(rc = lysp_stmt_parse(pctx, stmt, VOIDPTR_C(substmt->storage), NULL), cleanup);
         break;
 
     default:
diff --git a/src/plugins_exts.c b/src/plugins_exts.c
index e7626a2..cffbe53 100644
--- a/src/plugins_exts.c
+++ b/src/plugins_exts.c
@@ -101,7 +101,7 @@
         ly_bool enabled;
 
         /* evaluate */
-        LY_CHECK_GOTO(rc = lys_eval_iffeatures(ctx->ctx, (struct lysp_qname *)parsed, &enabled), cleanup);
+        LY_CHECK_GOTO(rc = lys_eval_iffeatures(ctx->ctx, VOIDPTR_C(parsed), &enabled), cleanup);
         if (!enabled) {
             /* it is disabled, remove the whole extension instance */
             rc = LY_ENOT;
@@ -133,7 +133,7 @@
         struct lysc_node *node;
 
         lyplg_ext_get_storage(ext, LY_STMT_STATUS, sizeof flags, (const void **)&flags);
-        pnodes = (struct lysp_node *)parsed;
+        pnodes = VOIDPTR_C(parsed);
 
         /* compile nodes */
         LY_LIST_FOR(pnodes, pnode) {
@@ -163,7 +163,7 @@
     case LY_STMT_REFERENCE:
     case LY_STMT_UNITS:
         /* just make a copy */
-        LY_CHECK_GOTO(rc = lydict_insert(ctx->ctx, (const char *)parsed, 0, (const char **)substmt->storage), cleanup);
+        LY_CHECK_GOTO(rc = lydict_insert(ctx->ctx, VOIDPTR_C(parsed), 0, VOIDPTR_C(substmt->storage)), cleanup);
         break;
 
     case LY_STMT_BIT:
@@ -175,8 +175,7 @@
         }
 
         /* compile */
-        rc = lys_compile_type_enums(ctx, (struct lysp_type_enum *)parsed, basetype, NULL,
-                (struct lysc_type_bitenum_item **)substmt->storage);
+        rc = lys_compile_type_enums(ctx, VOIDPTR_C(parsed), basetype, NULL, VOIDPTR_C(substmt->storage));
         LY_CHECK_GOTO(rc, cleanup);
         break;
 
@@ -195,56 +194,56 @@
                 /* default config */
                 flags = LYS_CONFIG_W;
             }
-            memcpy((void *)substmt->storage, &flags, 2);
+            memcpy(VOIDPTR_C(substmt->storage), &flags, 2);
         } /* else leave zero */
         break;
     }
     case LY_STMT_MUST: {
-        const struct lysp_restr *restrs = (struct lysp_restr *)parsed;
+        const struct lysp_restr *restrs = VOIDPTR_C(parsed);
 
         /* sized array */
-        COMPILE_ARRAY_GOTO(ctx, restrs, *(struct lysc_must **)substmt->storage, lys_compile_must, rc, cleanup);
+        COMPILE_ARRAY_GOTO(ctx, restrs, *(struct lysc_must **)VOIDPTR_C(substmt->storage), lys_compile_must, rc, cleanup);
         break;
     }
     case LY_STMT_WHEN: {
         const uint16_t flags;
-        const struct lysp_when *when = (struct lysp_when *)parsed;
+        const struct lysp_when *when = VOIDPTR_C(parsed);
 
         /* read compiled status */
         lyplg_ext_get_storage(ext, LY_STMT_STATUS, sizeof flags, (const void **)&flags);
 
         /* compile */
-        LY_CHECK_GOTO(rc = lys_compile_when(ctx, when, flags, NULL, NULL, NULL, (struct lysc_when **)substmt->storage), cleanup);
+        LY_CHECK_GOTO(rc = lys_compile_when(ctx, when, flags, NULL, NULL, NULL, VOIDPTR_C(substmt->storage)), cleanup);
         break;
     }
     case LY_STMT_FRACTION_DIGITS:
     case LY_STMT_REQUIRE_INSTANCE:
         /* just make a copy */
-        memcpy((void *)substmt->storage, &parsed, 1);
+        memcpy(VOIDPTR_C(substmt->storage), &parsed, 1);
         break;
 
     case LY_STMT_MANDATORY:
     case LY_STMT_ORDERED_BY:
     case LY_STMT_STATUS:
         /* just make a copy */
-        memcpy((void *)substmt->storage, &parsed, 2);
+        memcpy(VOIDPTR_C(substmt->storage), &parsed, 2);
         break;
 
     case LY_STMT_MAX_ELEMENTS:
     case LY_STMT_MIN_ELEMENTS:
         /* just make a copy */
-        memcpy((void *)substmt->storage, &parsed, 4);
+        memcpy(VOIDPTR_C(substmt->storage), &parsed, 4);
         break;
 
     case LY_STMT_POSITION:
     case LY_STMT_VALUE:
         /* just make a copy */
-        memcpy((void *)substmt->storage, &parsed, 8);
+        memcpy(VOIDPTR_C(substmt->storage), &parsed, 8);
         break;
 
     case LY_STMT_IDENTITY:
         /* compile */
-        rc = lys_identity_precompile(ctx, NULL, NULL, (struct lysp_ident *)parsed, (struct lysc_ident **)substmt->storage);
+        rc = lys_identity_precompile(ctx, NULL, NULL, VOIDPTR_C(parsed), VOIDPTR_C(substmt->storage));
         LY_CHECK_GOTO(rc, cleanup);
         break;
 
@@ -253,37 +252,36 @@
     /* fallthrough */
     case LY_STMT_RANGE:
         /* compile, use uint64 default range */
-        rc = lys_compile_type_range(ctx, (struct lysp_restr *)parsed, LY_TYPE_UINT64, length_restr, 0, NULL,
-                (struct lysc_range **)substmt->storage);
+        rc = lys_compile_type_range(ctx, VOIDPTR_C(parsed), LY_TYPE_UINT64, length_restr, 0, NULL, VOIDPTR_C(substmt->storage));
         LY_CHECK_GOTO(rc, cleanup);
         break;
 
     case LY_STMT_PATTERN:
         /* compile */
-        rc = lys_compile_type_patterns(ctx, (struct lysp_restr *)parsed, NULL, (struct lysc_pattern ***)substmt->storage);
+        rc = lys_compile_type_patterns(ctx, VOIDPTR_C(parsed), NULL, VOIDPTR_C(substmt->storage));
         LY_CHECK_GOTO(rc, cleanup);
         break;
 
     case LY_STMT_TYPE: {
         const uint16_t flags;
         const char *units;
-        const struct lysp_type *ptype = (struct lysp_type *)parsed;
+        const struct lysp_type *ptype = VOIDPTR_C(parsed);
 
         /* read compiled info */
         lyplg_ext_get_storage(ext, LY_STMT_STATUS, sizeof flags, (const void **)&flags);
         lyplg_ext_get_storage(ext, LY_STMT_UNITS, sizeof units, (const void **)&units);
 
         /* compile */
-        rc = lys_compile_type(ctx, NULL, flags, ext->def->name, ptype, (struct lysc_type **)substmt->storage, &units, NULL);
+        rc = lys_compile_type(ctx, NULL, flags, ext->def->name, ptype, VOIDPTR_C(substmt->storage), &units, NULL);
         LY_CHECK_GOTO(rc, cleanup);
-        LY_ATOMIC_INC_BARRIER((*(struct lysc_type **)substmt->storage)->refcount);
+        LY_ATOMIC_INC_BARRIER((*(struct lysc_type **)VOIDPTR_C(substmt->storage))->refcount);
         break;
     }
     case LY_STMT_EXTENSION_INSTANCE: {
-        struct lysp_ext_instance *extps = (struct lysp_ext_instance *)parsed;
+        struct lysp_ext_instance *extps = VOIDPTR_C(parsed);
 
         /* compile sized array */
-        COMPILE_EXTS_GOTO(ctx, extps, *(struct lysc_ext_instance **)substmt->storage, ext, rc, cleanup);
+        COMPILE_EXTS_GOTO(ctx, extps, *(struct lysc_ext_instance **)VOIDPTR_C(substmt->storage), ext, rc, cleanup);
         break;
     }
     case LY_STMT_AUGMENT:
@@ -342,9 +340,9 @@
 
     LY_ARRAY_FOR(extp->substmts, u) {
         stmtp = extp->substmts[u].stmt;
-        storagep = *(uint64_t *)extp->substmts[u].storage;
+        storagep = *(uint64_t *)VOIDPTR_C(extp->substmts[u].storage);
 
-        if (!storagep || ly_set_contains(&storagep_compiled, (void *)storagep, NULL)) {
+        if (!storagep || ly_set_contains(&storagep_compiled, VOIDPTR_C(storagep), NULL)) {
             /* nothing parsed or already compiled (for example, if it is a linked list of parsed nodes) */
             continue;
         }
@@ -363,7 +361,7 @@
         }
 
         /* compiled */
-        ly_set_add(&storagep_compiled, (void *)storagep, 1, NULL);
+        ly_set_add(&storagep_compiled, VOIDPTR_C(storagep), 1, NULL);
     }
 
 cleanup:
@@ -439,7 +437,7 @@
         case LY_STMT_LEAF:
         case LY_STMT_LEAF_LIST:
         case LY_STMT_LIST:
-            schema = *((struct lysc_node **)ext->substmts[i].storage);
+            schema = *VOIDPTR2_C(ext->substmts[i].storage);
             if (schema) {
                 rc = lyplg_ext_sprinter_ctree_add_nodes(ctx, schema, clb);
                 return rc;
@@ -477,7 +475,7 @@
         case LY_STMT_LEAF:
         case LY_STMT_LEAF_LIST:
         case LY_STMT_LIST:
-            schema = *((struct lysp_node **)ext->substmts[i].storage);
+            schema = *VOIDPTR2_C(ext->substmts[i].storage);
             if (schema) {
                 rc = lyplg_ext_sprinter_ptree_add_nodes(ctx, schema, clb);
                 return rc;
@@ -622,7 +620,7 @@
 
     /* assign */
     if (s) {
-        memcpy(storage, (void *)s, storage_size);
+        memcpy(storage, VOIDPTR_C(s), storage_size);
     } else {
         memset(storage, 0, storage_size);
     }
@@ -664,7 +662,7 @@
 
     /* assign */
     if (s) {
-        memcpy(storage, (void *)s, storage_size);
+        memcpy(storage, VOIDPTR_C(s), storage_size);
     } else {
         memset(storage, 0, storage_size);
     }
diff --git a/src/printer_yang.c b/src/printer_yang.c
index c5e4b11..6dc06a8 100644
--- a/src/printer_yang.c
+++ b/src/printer_yang.c
@@ -2563,7 +2563,7 @@
                 break;
             }
 
-            LY_LIST_FOR(*(const struct lysc_node **)ext->substmts[u].storage, node) {
+            LY_LIST_FOR(*VOIDPTR2_C(ext->substmts[u].storage), node) {
                 ypr_open(pctx->out, flag);
                 if (ext->substmts[u].stmt == LY_STMT_NOTIFICATION) {
                     yprc_notification(pctx, (struct lysc_node_notif *)node);
@@ -2592,32 +2592,32 @@
         case LY_STMT_PRESENCE:
         case LY_STMT_REFERENCE:
         case LY_STMT_UNITS:
-            if (*(const char **)ext->substmts[u].storage) {
+            if (*VOIDPTR2_C(ext->substmts[u].storage)) {
                 ypr_open(pctx->out, flag);
-                ypr_substmt(pctx, ext->substmts[u].stmt, 0, *(const char **)ext->substmts[u].storage, 0, ext->exts);
+                ypr_substmt(pctx, ext->substmts[u].stmt, 0, *VOIDPTR2_C(ext->substmts[u].storage), 0, ext->exts);
             }
             break;
         case LY_STMT_BIT:
         case LY_STMT_ENUM: {
-            const struct lysc_type_bitenum_item *items = *(struct lysc_type_bitenum_item **)ext->substmts[u].storage;
+            const struct lysc_type_bitenum_item *items = *VOIDPTR2_C(ext->substmts[u].storage);
 
             yprc_bits_enum(pctx, items, ext->substmts[u].stmt == LY_STMT_BIT ? LY_TYPE_BITS : LY_TYPE_ENUM, flag);
             break;
         }
         case LY_STMT_CONFIG:
-            ypr_config(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
+            ypr_config(pctx, *(uint16_t *)VOIDPTR2_C(ext->substmts[u].storage), ext->exts, flag);
             break;
         case LY_STMT_EXTENSION_INSTANCE:
-            yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0,
-                    *(struct lysc_ext_instance **)ext->substmts[u].storage, flag);
+            yprc_extension_instances(pctx, LY_STMT_EXTENSION_INSTANCE, 0, *VOIDPTR2_C(ext->substmts[u].storage), flag);
             break;
         case LY_STMT_FRACTION_DIGITS:
-            if (*(uint8_t *)ext->substmts[u].storage) {
-                ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts, *(uint8_t *)ext->substmts[u].storage, flag);
+            if (*VOIDPTR2_C(ext->substmts[u].storage)) {
+                ypr_unsigned(pctx, LY_STMT_FRACTION_DIGITS, 0, ext->exts,
+                        (long unsigned int)*VOIDPTR2_C(ext->substmts[u].storage), flag);
             }
             break;
         case LY_STMT_IDENTITY: {
-            const struct lysc_ident *idents = *(struct lysc_ident **)ext->substmts[u].storage;
+            const struct lysc_ident *idents = *VOIDPTR2_C(ext->substmts[u].storage);
 
             LY_ARRAY_FOR(idents, v) {
                 yprc_identity(pctx, &idents[v]);
@@ -2625,15 +2625,15 @@
             break;
         }
         case LY_STMT_LENGTH:
-            if (*(struct lysc_range **)ext->substmts[u].storage) {
-                yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_STRING, flag);
+            if (*VOIDPTR2_C(ext->substmts[u].storage)) {
+                yprc_range(pctx, *VOIDPTR2_C(ext->substmts[u].storage), LY_TYPE_STRING, flag);
             }
             break;
         case LY_STMT_MANDATORY:
-            ypr_mandatory(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
+            ypr_mandatory(pctx, *(uint16_t *)VOIDPTR_C(ext->substmts[u].storage), ext->exts, flag);
             break;
         case LY_STMT_MAX_ELEMENTS: {
-            uint32_t max = *(uint32_t *)ext->substmts[u].storage;
+            uint32_t max = *(uint32_t *)VOIDPTR_C(ext->substmts[u].storage);
 
             if (max) {
                 ypr_unsigned(pctx, LY_STMT_MAX_ELEMENTS, 0, ext->exts, max, flag);
@@ -2644,15 +2644,15 @@
             break;
         }
         case LY_STMT_MIN_ELEMENTS:
-            ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)ext->substmts[u].storage, flag);
+            ypr_unsigned(pctx, LY_STMT_MIN_ELEMENTS, 0, ext->exts, *(uint32_t *)VOIDPTR_C(ext->substmts[u].storage), flag);
             break;
         case LY_STMT_ORDERED_BY:
             ypr_open(pctx->out, flag);
             ypr_substmt(pctx, LY_STMT_ORDERED_BY, 0,
-                    (*(uint16_t *)ext->substmts[u].storage & LYS_ORDBY_USER) ? "user" : "system", 0, ext->exts);
+                    ((*(uint16_t *)VOIDPTR_C(ext->substmts[u].storage)) & LYS_ORDBY_USER) ? "user" : "system", 0, ext->exts);
             break;
         case LY_STMT_MUST: {
-            const struct lysc_must *musts = *(struct lysc_must **)ext->substmts[u].storage;
+            const struct lysc_must *musts = *VOIDPTR2_C(ext->substmts[u].storage);
 
             LY_ARRAY_FOR(musts, v) {
                 yprc_must(pctx, &musts[v], flag);
@@ -2660,7 +2660,7 @@
             break;
         }
         case LY_STMT_PATTERN: {
-            const struct lysc_pattern *patterns = *(struct lysc_pattern **)ext->substmts[u].storage;
+            const struct lysc_pattern *patterns = *VOIDPTR2_C(ext->substmts[u].storage);
 
             LY_ARRAY_FOR(patterns, v) {
                 yprc_pattern(pctx, &patterns[v], flag);
@@ -2668,36 +2668,36 @@
             break;
         }
         case LY_STMT_POSITION:
-            if (*(int64_t *)ext->substmts[u].storage) {
-                ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
+            if (*VOIDPTR2_C(ext->substmts[u].storage)) {
+                ypr_unsigned(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)VOIDPTR_C(ext->substmts[u].storage), flag);
             }
             break;
         case LY_STMT_VALUE:
-            if (*(int64_t *)ext->substmts[u].storage) {
-                ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)ext->substmts[u].storage, flag);
+            if (*VOIDPTR2_C(ext->substmts[u].storage)) {
+                ypr_signed(pctx, ext->substmts[u].stmt, 0, ext->exts, *(int64_t *)VOIDPTR_C(ext->substmts[u].storage), flag);
             }
             break;
         case LY_STMT_RANGE:
-            if (*(struct lysc_range **)ext->substmts[u].storage) {
-                yprc_range(pctx, *(struct lysc_range **)ext->substmts[u].storage, LY_TYPE_UINT64, flag);
+            if (*VOIDPTR2_C(ext->substmts[u].storage)) {
+                yprc_range(pctx, *VOIDPTR2_C(ext->substmts[u].storage), LY_TYPE_UINT64, flag);
             }
             break;
         case LY_STMT_REQUIRE_INSTANCE:
             ypr_open(pctx->out, flag);
-            ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)ext->substmts[u].storage ? "true" : "false",
+            ypr_substmt(pctx, LY_STMT_REQUIRE_INSTANCE, 0, *(uint8_t *)VOIDPTR_C(ext->substmts[u].storage) ? "true" : "false",
                     0, ext->exts);
             break;
         case LY_STMT_STATUS:
-            ypr_status(pctx, *(uint16_t *)ext->substmts[u].storage, ext->exts, flag);
+            ypr_status(pctx, *(uint16_t *)VOIDPTR_C(ext->substmts[u].storage), ext->exts, flag);
             break;
         case LY_STMT_TYPE:
-            if (*(const struct lysc_type **)ext->substmts[u].storage) {
+            if (*VOIDPTR2_C(ext->substmts[u].storage)) {
                 ypr_open(pctx->out, flag);
-                yprc_type(pctx, *(const struct lysc_type **)ext->substmts[u].storage);
+                yprc_type(pctx, *VOIDPTR2_C(ext->substmts[u].storage));
             }
             break;
         case LY_STMT_WHEN:
-            yprc_when(pctx, *(struct lysc_when **)ext->substmts[u].storage, flag);
+            yprc_when(pctx, *VOIDPTR2_C(ext->substmts[u].storage), flag);
             break;
         case LY_STMT_AUGMENT:
         case LY_STMT_BASE:
diff --git a/src/schema_compile_amend.c b/src/schema_compile_amend.c
index 321ff94..4eac4ec 100644
--- a/src/schema_compile_amend.c
+++ b/src/schema_compile_amend.c
@@ -2218,7 +2218,7 @@
         aug_p = NULL;
         LY_ARRAY_FOR(pmod->exts[u].substmts, v) {
             if (pmod->exts[u].substmts[v].stmt == LY_STMT_AUGMENT) {
-                aug_p = *(struct lysp_node_augment **)pmod->exts[u].substmts[v].storage;
+                aug_p = *VOIDPTR2_C(pmod->exts[u].substmts[v].storage);
                 break;
             }
         }
@@ -2488,7 +2488,7 @@
         aug = NULL;
         LY_ARRAY_FOR(pmod->exts[u].substmts, v) {
             if (pmod->exts[u].substmts[v].stmt == LY_STMT_AUGMENT) {
-                aug = *(struct lysp_node_augment **)pmod->exts[u].substmts[v].storage;
+                aug = *VOIDPTR2_C(pmod->exts[u].substmts[v].storage);
                 break;
             }
         }
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index 145ae8f..91ba72b 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -1383,75 +1383,75 @@
         case LY_STMT_USES: {
             struct lysp_node *child, *child_next;
 
-            LY_LIST_FOR_SAFE(*((struct lysp_node **)substmts[u].storage), child_next, child) {
+            LY_LIST_FOR_SAFE(*VOIDPTR2_C(substmts[u].storage), child_next, child) {
                 node_free = (child->nodetype & (LYS_INPUT | LYS_OUTPUT)) ? 1 : 0;
                 lysp_node_free(&fctx, child);
                 if (node_free) {
                     free(child);
                 }
             }
-            *((struct lysc_node **)substmts[u].storage) = NULL;
+            *VOIDPTR2_C(substmts[u].storage) = NULL;
             break;
         }
         case LY_STMT_BASE:
             /* multiple strings */
-            FREE_ARRAY(ctx, **(const char ***)substmts[u].storage, lydict_remove);
+            FREE_ARRAY(ctx, **(const char ***)VOIDPTR2_C(substmts[u].storage), lydict_remove);
             break;
 
         case LY_STMT_BIT:
         case LY_STMT_ENUM:
             /* single enum */
-            lysp_type_enum_free(&fctx, *(struct lysp_type_enum **)substmts[u].storage);
+            lysp_type_enum_free(&fctx, *VOIDPTR2_C(substmts[u].storage));
             break;
 
         case LY_STMT_DEVIATE:
             /* single deviate */
-            lysp_deviate_free(&fctx, *(struct lysp_deviate **)substmts[u].storage);
+            lysp_deviate_free(&fctx, *VOIDPTR2_C(substmts[u].storage));
             break;
 
         case LY_STMT_DEVIATION:
             /* single deviation */
-            lysp_deviation_free(&fctx, *(struct lysp_deviation **)substmts[u].storage);
+            lysp_deviation_free(&fctx, *VOIDPTR2_C(substmts[u].storage));
             break;
 
         case LY_STMT_EXTENSION:
             /* single extension */
-            lysp_ext_free(&fctx, *(struct lysp_ext **)substmts[u].storage);
+            lysp_ext_free(&fctx, *VOIDPTR2_C(substmts[u].storage));
             break;
 
         case LY_STMT_EXTENSION_INSTANCE:
             /* multiple extension instances */
-            FREE_ARRAY(&fctx, *(struct lysp_ext_instance **)substmts[u].storage, lysp_ext_instance_free);
+            FREE_ARRAY(&fctx, *(struct lysp_ext_instance **)VOIDPTR2_C(substmts[u].storage), lysp_ext_instance_free);
             break;
 
         case LY_STMT_FEATURE:
             /* multiple features */
-            FREE_ARRAY(&fctx, *(struct lysp_feature **)substmts[u].storage, lysp_feature_free);
+            FREE_ARRAY(&fctx, *(struct lysp_feature **)VOIDPTR2_C(substmts[u].storage), lysp_feature_free);
             break;
 
         case LY_STMT_IDENTITY:
             /* multiple identities */
-            FREE_ARRAY(&fctx, *(struct lysp_ident **)substmts[u].storage, lysp_ident_free);
+            FREE_ARRAY(&fctx, *(struct lysp_ident **)VOIDPTR2_C(substmts[u].storage), lysp_ident_free);
             break;
 
         case LY_STMT_IMPORT:
             /* multiple imports */
-            FREE_ARRAY(&fctx, *(struct lysp_import **)substmts[u].storage, lysp_import_free);
+            FREE_ARRAY(&fctx, *(struct lysp_import **)VOIDPTR2_C(substmts[u].storage), lysp_import_free);
             break;
 
         case LY_STMT_INCLUDE:
             /* multiple includes */
-            FREE_ARRAY(&fctx, *(struct lysp_include **)substmts[u].storage, lysp_include_free);
+            FREE_ARRAY(&fctx, *(struct lysp_include **)VOIDPTR2_C(substmts[u].storage), lysp_include_free);
             break;
 
         case LY_STMT_REFINE:
             /* multiple refines */
-            FREE_ARRAY(&fctx, *(struct lysp_refine **)substmts[u].storage, lysp_refine_free);
+            FREE_ARRAY(&fctx, *(struct lysp_refine **)VOIDPTR2_C(substmts[u].storage), lysp_refine_free);
             break;
 
         case LY_STMT_REVISION:
             /* multiple revisions */
-            FREE_ARRAY(&fctx, *(struct lysp_revision **)substmts[u].storage, lysp_revision_free);
+            FREE_ARRAY(&fctx, *(struct lysp_revision **)VOIDPTR2_C(substmts[u].storage), lysp_revision_free);
             break;
 
         case LY_STMT_CONFIG:
@@ -1485,7 +1485,7 @@
         case LY_STMT_REVISION_DATE:
         case LY_STMT_UNITS:
             /* single string */
-            lydict_remove(ctx, *(const char **)substmts[u].storage);
+            lydict_remove(ctx, *VOIDPTR2_C(substmts[u].storage));
             break;
 
         case LY_STMT_LENGTH:
@@ -1493,34 +1493,34 @@
         case LY_STMT_PATTERN:
         case LY_STMT_RANGE:
             /* multiple restrictions */
-            FREE_ARRAY(&fctx, *(struct lysp_restr **)substmts[u].storage, lysp_restr_free);
+            FREE_ARRAY(&fctx, *(struct lysp_restr **)VOIDPTR2_C(substmts[u].storage), lysp_restr_free);
             break;
 
         case LY_STMT_WHEN:
             /* multiple whens */
-            FREE_ARRAY(&fctx, *(struct lysp_when **)substmts[u].storage, lysp_when_free);
+            FREE_ARRAY(&fctx, *(struct lysp_when **)VOIDPTR2_C(substmts[u].storage), lysp_when_free);
             break;
 
         case LY_STMT_PATH:
             /* single expression */
-            lyxp_expr_free(ctx, *(struct lyxp_expr **)substmts[u].storage);
+            lyxp_expr_free(ctx, *VOIDPTR2_C(substmts[u].storage));
             break;
 
         case LY_STMT_DEFAULT:
         case LY_STMT_IF_FEATURE:
         case LY_STMT_UNIQUE:
             /* multiple qnames */
-            FREE_ARRAY(ctx, *(struct lysp_qname **)substmts[u].storage, lysp_qname_free);
+            FREE_ARRAY(ctx, *(struct lysp_qname **)VOIDPTR2_C(substmts[u].storage), lysp_qname_free);
             break;
 
         case LY_STMT_TYPEDEF:
             /* multiple typedefs */
-            FREE_ARRAY(&fctx, *(struct lysp_tpdf **)substmts[u].storage, lysp_tpdf_free);
+            FREE_ARRAY(&fctx, *(struct lysp_tpdf **)VOIDPTR2_C(substmts[u].storage), lysp_tpdf_free);
             break;
 
         case LY_STMT_TYPE: {
             /* single type */
-            struct lysp_type **type_p = (void *)substmts[u].storage;
+            struct lysp_type **type_p = VOIDPTR_C(substmts[u].storage);
 
             lysp_type_free(&fctx, *type_p);
             free(*type_p);
@@ -1529,7 +1529,7 @@
         case LY_STMT_MODULE:
         case LY_STMT_SUBMODULE:
             /* single (sub)module */
-            lysp_module_free(&fctx, *(struct lysp_module **)substmts[u].storage);
+            lysp_module_free(&fctx, *VOIDPTR2_C(substmts[u].storage));
             break;
 
         default:
@@ -1568,14 +1568,14 @@
         case LY_STMT_LIST: {
             struct lysc_node *child, *child_next;
 
-            LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) {
+            LY_LIST_FOR_SAFE(*VOIDPTR2_C(substmts[u].storage), child_next, child) {
                 node_free = (child->nodetype & (LYS_INPUT | LYS_OUTPUT)) ? 1 : 0;
                 lysc_node_free_(&fctx, child);
                 if (node_free) {
                     free(child);
                 }
             }
-            *((struct lysc_node **)substmts[u].storage) = NULL;
+            *VOIDPTR2_C(substmts[u].storage) = NULL;
             break;
         }
         case LY_STMT_USES:
@@ -1605,7 +1605,7 @@
         case LY_STMT_REFERENCE:
         case LY_STMT_UNITS: {
             /* single item */
-            const char *str = *((const char **)substmts[u].storage);
+            const char *str = *VOIDPTR2_C(substmts[u].storage);
 
             lydict_remove(ctx, str);
             break;
@@ -1613,7 +1613,7 @@
         case LY_STMT_BIT:
         case LY_STMT_ENUM: {
             /* sized array */
-            struct lysc_type_bitenum_item *items = *((struct lysc_type_bitenum_item **)substmts[u].storage);
+            struct lysc_type_bitenum_item *items = *VOIDPTR2_C(substmts[u].storage);
 
             FREE_ARRAY(&fctx, items, lysc_enum_item_free);
             break;
@@ -1621,47 +1621,47 @@
         case LY_STMT_LENGTH:
         case LY_STMT_RANGE: {
             /* single item */
-            struct lysc_range *range = *((struct lysc_range **)substmts[u].storage);
+            struct lysc_range *range = *VOIDPTR2_C(substmts[u].storage);
 
             lysc_range_free(&fctx, range);
             break;
         }
         case LY_STMT_MUST: {
             /* sized array */
-            struct lysc_must *musts = *((struct lysc_must **)substmts[u].storage);
+            struct lysc_must *musts = *VOIDPTR2_C(substmts[u].storage);
 
             FREE_ARRAY(&fctx, musts, lysc_must_free);
             break;
         }
         case LY_STMT_WHEN:
             /* single item, expects a pointer */
-            lysc_when_free(&fctx, (struct lysc_when **)substmts[u].storage);
+            lysc_when_free(&fctx, VOIDPTR_C(substmts[u].storage));
             break;
 
         case LY_STMT_PATTERN: {
             /* sized array of pointers */
-            struct lysc_pattern **patterns = *((struct lysc_pattern ***)substmts[u].storage);
+            struct lysc_pattern **patterns = *VOIDPTR2_C(substmts[u].storage);
 
             FREE_ARRAY(&fctx, patterns, lysc_pattern_free);
             break;
         }
         case LY_STMT_TYPE: {
             /* single item */
-            struct lysc_type *type = *((struct lysc_type **)substmts[u].storage);
+            struct lysc_type *type = *VOIDPTR2_C(substmts[u].storage);
 
             lysc_type_free(&fctx, type);
             break;
         }
         case LY_STMT_IDENTITY: {
             /* sized array */
-            struct lysc_ident *idents = *((struct lysc_ident **)substmts[u].storage);
+            struct lysc_ident *idents = *VOIDPTR2_C(substmts[u].storage);
 
             FREE_ARRAY(&fctx, idents, lysc_ident_free);
             break;
         }
         case LY_STMT_EXTENSION_INSTANCE: {
             /* sized array */
-            struct lysc_ext_instance *exts = *((struct lysc_ext_instance **)substmts[u].storage);
+            struct lysc_ext_instance *exts = *VOIDPTR2_C(substmts[u].storage);
 
             FREE_ARRAY(&fctx, exts, lysc_ext_instance_free);
             break;
diff --git a/tests/utests/schema/test_schema.c b/tests/utests/schema/test_schema.c
index 2dd7f6d..953aad8 100644
--- a/tests/utests/schema/test_schema.c
+++ b/tests/utests/schema/test_schema.c
@@ -1712,7 +1712,7 @@
     LY_ARRAY_NEW_GOTO(UTEST_LYCTX, ext_p.substmts, substmtp, rc, cleanup);
 
     substmtp->stmt = LY_STMT_ERROR_MESSAGE;
-    substmtp->storage = &ext_p.parsed;
+    substmtp->storage = (uintptr_t)(void *)&ext_p.parsed;
     /* fake parse */
     lydict_insert(UTEST_LYCTX, "my error", 0, (const char **)&ext_p.parsed);
 
@@ -1721,7 +1721,7 @@
     LY_ARRAY_NEW_GOTO(UTEST_LYCTX, ext_c.substmts, substmt, rc, cleanup);
 
     substmt->stmt = LY_STMT_ERROR_MESSAGE;
-    substmt->storage = &ext_c.compiled;
+    substmt->storage = (uintptr_t)(void *)&ext_c.compiled;
 
     /*
      * error-message