diff --git a/mex/sources/build_matlab.m b/mex/sources/build_matlab.m
index 208167bbc8c21136c175cb9adbd9e02aa12b9269..1138f75515f7f4bb16e7aef078d64fa56fbfce58 100644
--- a/mex/sources/build_matlab.m
+++ b/mex/sources/build_matlab.m
@@ -49,7 +49,7 @@ else
     error('Unsupported platform')
 end
 
-% mwSize and mwIndex appeared in Matlab 7.3
+% mwSize, mwIndex and mwSignedIndex appeared in Matlab 7.3
 if matlab_ver_less_than('7.3')
     COMPILE_OPTIONS = [ COMPILE_OPTIONS ' -DMWTYPES_NOT_DEFINED' ];
 end
diff --git a/mex/sources/mjdgges/mjdgges.c b/mex/sources/mjdgges/mjdgges.c
index a24995608f12b4ab7fc0209488fa5f5ef3c40f48..77c4337cfe76a063630f88c939bb002b8122fec9 100644
--- a/mex/sources/mjdgges/mjdgges.c
+++ b/mex/sources/mjdgges/mjdgges.c
@@ -20,6 +20,10 @@
 #include <string.h>
 #include "mex.h"
 
+#if defined(MWTYPES_NOT_DEFINED) || defined(OCTAVE)
+typedef int mwSignedIndex;
+#endif
+
 #ifdef NO_LAPACK_H
 # if defined(__linux__) || defined(OCTAVE)
 #  define dgges dgges_
@@ -32,26 +36,26 @@ void dgges(char *, char *, char *, int (*)(), int *, double *, int *, double *,
 
 double criterium;
 
-int my_criteria(double *alphar, double *alphai, double *beta)
+mwSignedIndex my_criteria(double *alphar, double *alphai, double *beta)
 {
   return( (*alphar * *alphar + *alphai * *alphai) < criterium * *beta * *beta);
 }
 
 void mjdgges(double *a, double *b, double *z, double *n, double *sdim, double *eval_r, double *eval_i, double *info)
 {
-  int i_n, i_info, i_sdim, one, lwork;
+  mwSignedIndex i_n, i_info, i_sdim, one, lwork;
   double *alphar, *alphai, *beta, *work, *par, *pai, *pb, *per, *pei;
   double *junk;
-  int *bwork;
+  mwSignedIndex *bwork;
 
   one = 1;
-  i_n = (int)*n;
+  i_n = (mwSignedIndex)*n;
   alphar = mxCalloc(i_n,sizeof(double));
   alphai = mxCalloc(i_n,sizeof(double));
   beta = mxCalloc(i_n,sizeof(double));
   lwork = 16*i_n+16;
   work = mxCalloc(lwork,sizeof(double));
-  bwork = mxCalloc(i_n,sizeof(int));
+  bwork = mxCalloc(i_n,sizeof(mwSignedIndex));
   /* made necessary by bug in Lapack */
   junk = mxCalloc(i_n*i_n,sizeof(double));