Skip to content

Variable declarations in middle of function not supported by MSVC #3

@twylite

Description

@twylite

Discovered while trying to build revision df1899c using MSVC10: C code in zmk.tcl cannot build under MSVC since at least revision 68438a2 as this change introduced two instances of a variable being declared after code in the body of a function. Such a declaration is legitimate C99 code, but MSVC only supports C89 or C++.

This follow diff shows the minor correction required to build under MSVC:

--- tclzmq\zmq.tcl
+++ tclzmq\zmq.tcl
@@ -417,16 +417,17 @@
     }

     static int cget_context_option_as_tcl_obj(ClientData cd, Tcl_Interp* ip, Tcl_Obj* optObj, Tcl_Obj** result)
     {
        int name = 0;
+        int val = -1;
        void* zmqp = ((ZmqContextClientData*)cd)->context;
        ZmqClientData* zmqClientData = ((ZmqContextClientData*)cd)->zmqClientData;
        *result = 0;
        if (get_context_option(ip, optObj, &name) != TCL_OK)
            return TCL_ERROR;
-       int val = zmq_ctx_get(zmqp, name);
+       val = zmq_ctx_get(zmqp, name);
        last_zmq_errno = zmq_errno();
        if (val < 0) {
            *result = Tcl_NewStringObj(zmq_strerror(last_zmq_errno), -1);
            return TCL_ERROR;
        }
@@ -447,13 +448,13 @@
     {
        int name = 0;
        void* zmqp = ((ZmqContextClientData*)cd)->context;
        ZmqClientData* zmqClientData = ((ZmqContextClientData*)cd)->zmqClientData;
        int rt = 0;
+       int val = -1;
        if (get_context_option(ip, optObj, &name) != TCL_OK)
            return TCL_ERROR;
-       int val = -1;
        if (Tcl_GetIntFromObj(ip, valObj, &val) != TCL_OK) {
            Tcl_SetObjResult(ip, Tcl_NewStringObj("Wrong option value, expected integer", -1));
            return TCL_ERROR;
        }
        rt = zmq_ctx_set(zmqp, name, val);

Regards,
Twylite

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions