Thread: List of MEX Warnings

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    78

    List of MEX Warnings

    Hi guys!

    I'm trying to run someone else's MATLAB code, which contains a list of unclean c-Files.
    I get a huge list of errors while compiling the c files as MEX.

    getK_fast.c: In function 'mexFunction':
    getK_fast.c:20: warning: assignment discards qualifiers from pointer target type
    getK_fast.c:23: warning: assignment discards qualifiers from pointer target type
    getK_fast.c:33: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c: In function 'mexFunction':
    splat3_fast.c:42: warning: passing argument 4 of 'mxCreateStructMatrix_700' from incompatible pointer type
    splat3_fast.c:44: warning: assignment discards qualifiers from pointer target type
    splat3_fast.c:47: warning: assignment discards qualifiers from pointer target type
    splat3_fast.c:50: warning: assignment discards qualifiers from pointer target type
    splat3_fast.c:57: warning: assignment from incompatible pointer type
    splat3_fast.c:102: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:109: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:110: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:111: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:112: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:113: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:114: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:115: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:116: warning: passing argument 2 of 'mxCreateNumericArray_700' from incompatible pointer type
    splat3_fast.c:133: warning: assignment from incompatible pointer type
    splat3_fast.c:134: warning: assignment from incompatible pointer type
    splat3_fast.c:135: warning: assignment from incompatible pointer type
    splat3_fast.c:136: warning: assignment from incompatible pointer type
    splat3_fast.c:137: warning: assignment from incompatible pointer type
    splat3_fast.c:138: warning: assignment from incompatible pointer type
    splat3_fast.c:139: warning: assignment from incompatible pointer type
    splat3_fast.c:140: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c: In function 'mexFunction':
    splat3_backprop_fast.c:21: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:22: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:23: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:24: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:25: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:26: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:27: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:28: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:29: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:30: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:31: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:32: warning: assignment discards qualifiers from pointer target type
    splat3_backprop_fast.c:42: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:43: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:44: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:45: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:46: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:47: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:48: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:49: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:54: warning: assignment from incompatible pointer type
    interp1_fixed_sum_fast.c: In function 'mexFunction':
    interp1_fixed_sum_fast.c:19: warning: assignment discards qualifiers from pointer target type
    interp1_fixed_sum_fast.c:25: warning: assignment discards qualifiers from pointer target type


    I'm posting the respective code lines now.

    Lines 41 - 47 for splat3_fast.c

    Code:
      char *fields[18] = {"valid",  "span", "n_bins", "bin_width", "bin_area", "dims", "N", "idx111",  "idx112", "idx121", "idx122", "idx211", "idx212", "idx221", "idx222",  "f1", "f2"};  
      varargout[0] = mxCreateStructMatrix(1, 1, 17, fields);  
        
      X_mat = varargin[0];  
      X = mxGetPr(X_mat);  
        
      bin_range_low_mat = varargin[1];


    Lines 102 - 116 for splat3_fast.c

    Code:
    N_mat = mxCreateNumericArray(3, &int_dims, mxDOUBLE_CLASS, 0);  
      mxSetField(varargout[0], 0, "N", N_mat);  
      N = mxGetPr(N_mat);  
        
        
      sz_mat[0] = (int)n;  
      sz_mat[1] = (int)1;  
      idx111_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);  
      idx112_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);  
      idx121_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);  
      idx122_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);  
      idx211_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);  
      idx212_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);  
      idx221_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);  
      idx222_mat = mxCreateNumericArray(2, &sz_mat, mxUINT32_CLASS, 0);

    Lines 21 - 32 for splat3_backprop_fast.c:

    Code:
    d_loss_N_mat = varargin[0];  
      idx111_mat = varargin[1];  
      idx112_mat = varargin[2];  
      idx121_mat = varargin[3];  
      idx122_mat = varargin[4];  
      idx211_mat = varargin[5];  
      idx212_mat = varargin[6];  
      idx221_mat = varargin[7];  
      idx222_mat = varargin[8];  
      f1_mat = varargin[9];  
      f2_mat = varargin[10];  
      valid_mat = varargin[11];

    The next error clearly depends on the variables above.
    Lines 42 - 54 for splat3_backprop_fast.c
    Code:
    idx111 = mxGetPr(idx111_mat);  
      idx112 = mxGetPr(idx112_mat);  
      idx121 = mxGetPr(idx121_mat);  
      idx122 = mxGetPr(idx122_mat);  
      idx211 = mxGetPr(idx211_mat);  
      idx212 = mxGetPr(idx212_mat);  
      idx221 = mxGetPr(idx221_mat);  
      idx222 = mxGetPr(idx222_mat);  
        
      f1 = mxGetPr(f1_mat);  
      f2 = mxGetPr(f2_mat);  
        
      valid = mxGetPr(valid_mat);

    Und lastly:
    Lines 19, 25 for interp1_fixed_sum_fast.c

    Code:
      mxArray *X_mat, *LUT_F_mat;    
      X_mat = varargin[0];    
      LUT_F_mat = varargin[3];

    Any ideas of how to clean up this mess?

  2. #2
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    Those are warnings, not errors. Your code should still compile.

    edit: Some of these are fairly easy to fix. If you look at the first warning for which you've also provided code:

    splat3_fast.c:42: warning: passing argument 4 of 'mxCreateStructMatrix_700' from incompatible pointer type
    the code causing the warning:

    Code:
     char *fields[18] = {"valid",  "span", "n_bins", "bin_width", "bin_area", "dims", "N", "idx111",  "idx112", "idx121", "idx122", "idx211", "idx212", "idx221", "idx222",  "f1", "f2"};
    varargout[0] = mxCreateStructMatrix(1, 1, 17, fields);
    , and the prototype for the function mxCreateStructMatrix:

    Code:
    mxArray *mxCreateStructMatrix(int m, int n, int nfields, const char **field_names);
    * http://www.socsci.umn.edu/doc/matlab...uctmatrix.html

    you'll see that it's an easy fix. All you have to do is change the type of fields from char *[18] to const char *[18]. It seems like most of the other warnings can be fixed in a similar manner.
    Last edited by Barney McGrew; 11-24-2012 at 06:00 AM. Reason: fixed formatting

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by Barney McGrew View Post
    Those are warnings, not errors. Your code should still compile.
    While this is true , i would suggest to treat warnings as serious as errors. Especially when it comes to pointers , i think it is must to eliminate them all!

  4. #4
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Hey guys!

    Thanks for your suggestions!
    I did manage to do away with quite a few of them. Unfortunately, though. I'm still stuck with an incompatibility assignment error originating from the function mxGetPr.


    Here are the error messages:
    splat3_fast.c: In function 'mexFunction':
    splat3_fast.c:58: warning: assignment from incompatible pointer type
    splat3_fast.c:134: warning: assignment from incompatible pointer type
    splat3_fast.c:135: warning: assignment from incompatible pointer type
    splat3_fast.c:136: warning: assignment from incompatible pointer type
    splat3_fast.c:137: warning: assignment from incompatible pointer type
    splat3_fast.c:138: warning: assignment from incompatible pointer type
    splat3_fast.c:139: warning: assignment from incompatible pointer type
    splat3_fast.c:140: warning: assignment from incompatible pointer type
    splat3_fast.c:141: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c: In function 'mexFunction':
    splat3_backprop_fast.c:40: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:41: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:42: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:43: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:44: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:45: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:46: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:47: warning: assignment from incompatible pointer type
    splat3_backprop_fast.c:52: warning: assignment from incompatible pointer type
    splat3_fast.c
    Code:
    void mexFunction(int nargout, mxArray *varargout[], int nargin, const mxArray *varargin[])
    {
      
      const mxArray *X_mat, *bin_range_high_mat, *bin_range_low_mat;
      mxArray *valid_mat, *span_mat, *n_bins_mat, *bin_width_mat, *bin_area_mat, *dims_mat, *N_mat, *half_width_mat;
      double *X, *bin_range_low, *bin_range_high, sigma, *span, *n_bins, *bin_width, *bin_area, *dims, *N, *half_width;
      
      mxArray *idx111_mat, *idx112_mat, *idx121_mat, *idx122_mat, *idx211_mat, *idx212_mat, *idx221_mat, *idx222_mat, *f1_mat, *f2_mat;
      unsigned int *idx111, *idx112, *idx121, *idx122, *idx211, *idx212, *idx221, *idx222;
    ....
    ....
    ....
    ....
      valid_mat = mxCreateLogicalMatrix(n, 3);
      valid = mxGetPr(valid_mat);
    ....
    ....
    ....
      idx111 = mxGetPr(idx111_mat);
      idx112 = mxGetPr(idx112_mat);
      idx121 = mxGetPr(idx121_mat);
      idx122 = mxGetPr(idx122_mat);
      idx211 = mxGetPr(idx211_mat);
      idx212 = mxGetPr(idx212_mat);
      idx221 = mxGetPr(idx221_mat);
      idx222 = mxGetPr(idx222_mat);

    splat3_backprop_fast.c
    Code:
    void mexFunction(int nargout, mxArray *varargout[], int nargin, const mxArray *varargin[])
    {
      
      const mxArray *d_loss_N_mat, *d_loss_X_mat, *idx111_mat, *idx112_mat, *idx121_mat, *idx122_mat, *idx211_mat, *idx212_mat, *idx221_mat, *idx222_mat, *f1_mat, *f2_mat, *valid_mat;
    .....
    .....
      idx111_mat = varargin[1];
      idx112_mat = varargin[2];
      idx121_mat = varargin[3];
      idx122_mat = varargin[4];
      idx211_mat = varargin[5];
      idx212_mat = varargin[6];
      idx221_mat = varargin[7];
      idx222_mat = varargin[8];
      valid_mat = varargin[11];
    .....
    .....
      idx111 = mxGetPr(idx111_mat);
      idx112 = mxGetPr(idx112_mat);
      idx121 = mxGetPr(idx121_mat);
      idx122 = mxGetPr(idx122_mat);
      idx211 = mxGetPr(idx211_mat);
      idx212 = mxGetPr(idx212_mat);
      idx221 = mxGetPr(idx221_mat);
      idx222 = mxGetPr(idx222_mat);
    ....
      valid = mxGetPr(valid_mat);

    Any ideas on how to mend this?

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Code:
    *varargout[]
    this is a 2D array but you handle it like a 1D ..

  6. #6
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by std10093 View Post
    Code:
    *varargout[]
    this is a 2D array but you handle it like a 1D ..
    Hey std10093! Thanks for the hint.
    This seemed to work in all other files, so I did not think about this.

    How would you suggest changing the code?

  7. #7
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    The problem here is the return type of mxGetPtr. According to this reference (MathWorks Australia - Real data elements in array of type DOUBLE - MATLAB) it returns a pointer to double, whereas in your first code snippet you've assigned it to a pointer to unsigned int. The same problem seems to be causing the warnings in the second code snippet. In order to fix this, you just need to change the types of 'idx111'-'idx222' and 'valid' in both functions.

  8. #8
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by Barney McGrew View Post
    The problem here is the return type of mxGetPtr. According to this reference (MathWorks Australia - Real data elements in array of type DOUBLE - MATLAB) it returns a pointer to double, whereas in your first code snippet you've assigned it to a pointer to unsigned int. The same problem seems to be causing the warnings in the second code snippet. In order to fix this, you just need to change the types of 'idx111'-'idx222' and 'valid' in both functions.
    Hi there, Barney!

    Thanks for the heads-up!

    I did change 'idx111'-'idx222' and 'valid' to double in both functions. Unfortunately, though. These values are being used for array indexing later on in the code. Thus, after compiling, I received several errors:
    splat3_fast.c:197: error: array subscript is not an integer
    ....
    splat3_backprop_fast.c:56: error: array subscript is not an integer
    ....
    The error originate from the following lines of code:
    Code:
          idx122[i] = idx122[i] + ( (unsigned int) before)*dd[d];
          
        }
        
        idx121[i] = idx122[i] - dd[2];
        idx222[i] = idx122[i] + dd[0];
        idx221[i] = idx222[i] - dd[2];
        idx112[i] = idx122[i] - dd[1];
        idx111[i] = idx112[i] - dd[2];
        idx212[i] = idx222[i] - dd[1];
        idx211[i] = idx212[i] - dd[2];
            
        ff10ff11 = ff1[0] * ff1[1];
        ff10ff21 = ff1[0] * ff2[1];    
        ff20ff11 = ff2[0] * ff1[1];
        ff20ff21 = ff2[0] * ff2[1];
                
        N[idx111[i]-1] = N[idx111[i]-1] + ff10ff11 * ff1[2];
        N[idx121[i]-1] = N[idx121[i]-1] + ff10ff21 * ff1[2];
        N[idx211[i]-1] = N[idx211[i]-1] + ff20ff11 * ff1[2];
        N[idx221[i]-1] = N[idx221[i]-1] + ff20ff21 * ff1[2];
        N[idx112[i]-1] = N[idx112[i]-1] + ff10ff11 * ff2[2];
        N[idx122[i]-1] = N[idx122[i]-1] + ff10ff21 * ff2[2];
        N[idx212[i]-1] = N[idx212[i]-1] + ff20ff11 * ff2[2];
        N[idx222[i]-1] = N[idx222[i]-1] + ff20ff21 * ff2[2];
    I tried typecasting all N[idx***[i]-1] values to (insigned int), but this resulted in another set of error.
    Any suggestions?

  9. #9
    Stoned Witch Barney McGrew's Avatar
    Join Date
    Oct 2012
    Location
    astaylea
    Posts
    420
    I did change 'idx111'-'idx222' and 'valid' to double in both functions.
    Do you mean 'double *'? If so, the following should work:

    Code:
    N[(unsigned int) idx111[i] - 1] += ff10ff11 * ff1[2];
    ...

  10. #10
    Registered User
    Join Date
    Aug 2012
    Posts
    78
    Quote Originally Posted by Barney McGrew View Post
    Do you mean 'double *'? If so, the following should work:

    Code:
    N[(unsigned int) idx111[i] - 1] += ff10ff11 * ff1[2];
    ...

    Worked out perfectly! Many many thanks, Barney!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why i get these warnings..
    By transgalactic2 in forum C Programming
    Replies: 4
    Last Post: 03-25-2009, 10:31 AM
  2. Warnings with Pointer In Linked List
    By charIie in forum C Programming
    Replies: 8
    Last Post: 12-27-2007, 05:18 PM
  3. How DO I Get Rid Of Warnings?
    By bumfluff in forum Windows Programming
    Replies: 3
    Last Post: 11-24-2006, 06:34 PM
  4. GCC Warnings
    By 00Sven in forum C Programming
    Replies: 12
    Last Post: 05-03-2006, 04:40 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM