Quantcast
Channel: Intel® Software - Intel® oneAPI Math Kernel Library & Intel® Math Kernel Library
Viewing all articles
Browse latest Browse all 3005

Potential error in examples/cblas/common_func.c

$
0
0

When compiling CBLAS examples on Intel64 I get a number of related warnings, which indicate a benign error present in the example code:

common_func.c(863): warning #810: conversion from "CBLAS_LAYOUT={enum <unnamed>} *" to "int" may lose significant bits
             if ( (int)layout == CblasRowMajor )
                  ^

common_func.c(865): warning #810: conversion from "CBLAS_LAYOUT={enum <unnamed>} *" to "int" may lose significant bits
             else if ( (int)layout == CblasColMajor )
                       ^

common_func.c(869): warning #810: conversion from "CBLAS_SIDE={enum <unnamed>} *" to "int" may lose significant bits
              if ( (int)side == CblasLeft )
                   ^

common_func.c(871): warning #810: conversion from "CBLAS_SIDE={enum <unnamed>} *" to "int" may lose significant bits
              else if ( (int)side == CblasRight )
                        ^

common_func.c(875): warning #810: conversion from "CBLAS_UPLO={enum <unnamed>} *" to "int" may lose significant bits
              if ( (int)uplo == CblasUpper )
                   ^

common_func.c(877): warning #810: conversion from "CBLAS_UPLO={enum <unnamed>} *" to "int" may lose significant bits
             else if ( (int)uplo == CblasLower )
                       ^

common_func.c(881): warning #810: conversion from "CBLAS_DIAG={enum <unnamed>} *" to "int" may lose significant bits
              if ( (int)diag == CblasUnit )
                   ^

common_func.c(883): warning #810: conversion from "CBLAS_DIAG={enum <unnamed>} *" to "int" may lose significant bits
              else if ( (int)diag == CblasNonUnit )
                        ^

common_func.c(889): warning #810: conversion from "CBLAS_TRANSPOSE={enum <unnamed>} *" to "int" may lose significant bits
              if ( (int)trans == CblasNoTrans )
                   ^

common_func.c(891): warning #810: conversion from "CBLAS_TRANSPOSE={enum <unnamed>} *" to "int" may lose significant bits
              else if ( (int)trans == CblasTrans )
                        ^

common_func.c(893): warning #810: conversion from "CBLAS_TRANSPOSE={enum <unnamed>} *" to "int" may lose significant bits
              else if ( (int)trans == CblasConjTrans )

It seems that the compiler is right to complain - the PrintParameters function errorneously declares some variables as pointers, when in fact they should be plain enums. This works, but the code is in error - variables are declared as pointers, but are used as plain enums for comparison, and those pointers are not dereferenced anywhere.

With that in mind, for next release it should probably be patched as:

--- common_func.c       2014-09-07 21:52:49.615764023 +0200
+++ common_func.c       2014-09-07 22:42:58.929931820 +0200
@@ -833,11 +833,11 @@

 void PrintParameters( char *names, ... )
 {
-    CBLAS_LAYOUT    *layout;
-    CBLAS_SIDE      *side;
-    CBLAS_UPLO      *uplo;
-    CBLAS_DIAG      *diag;
-    CBLAS_TRANSPOSE *trans;
+    CBLAS_LAYOUT     layout;
+    CBLAS_SIDE       side;
+    CBLAS_UPLO       uplo;
+    CBLAS_DIAG       diag;
+    CBLAS_TRANSPOSE  trans;
     char            *p, *str, str1[MAX_STRING_LEN], buf[MAX_STRING_LEN];
     va_list          ap;
     char             seps[]=" ,";
@@ -859,38 +859,38 @@
           p++;
        }
        if ( strcmp( str1, "layout" ) == 0 ) {
-           layout = va_arg( ap, CBLAS_LAYOUT* );
-           if ( (int)layout == CblasRowMajor )
+           layout = va_arg( ap, CBLAS_LAYOUT );
+           if ( layout == CblasRowMajor )
                 printf("LAYOUT = CblasRowMajor  ");
-           else if ( (int)layout == CblasColMajor )
+           else if ( layout == CblasColMajor )
                 printf("LAYOUT = CblasColMajor  ");
        } else if ( strcmp( str1, "side" ) == 0 ) {
-            side = va_arg( ap, CBLAS_SIDE * );
-            if ( (int)side == CblasLeft )
+            side = va_arg( ap, CBLAS_SIDE );
+            if ( side == CblasLeft )
                printf("SIDE = CblasLeft  ");
-            else if ( (int)side == CblasRight )
+            else if ( side == CblasRight )
                printf("SIDE = CblasRight  ");
        } else if ( strcmp( str1, "uplo" ) == 0 ) {
-            uplo = va_arg( ap, CBLAS_UPLO * );
-            if ( (int)uplo == CblasUpper )
+            uplo = va_arg( ap, CBLAS_UPLO );
+            if ( uplo == CblasUpper )
                printf("UPLO = CblasUpper  ");
-           else if ( (int)uplo == CblasLower )
+           else if ( uplo == CblasLower )
                printf("UPLO = CblasLower  ");
        } else if ( strcmp( str1, "diag" ) == 0 ) {
-            diag = va_arg( ap, CBLAS_DIAG * );
-            if ( (int)diag == CblasUnit )
+            diag = va_arg( ap, CBLAS_DIAG );
+            if ( diag == CblasUnit )
                printf("DIAG=CblasUnit  ");
-            else if ( (int)diag == CblasNonUnit )
+            else if ( diag == CblasNonUnit )
                printf("DIAG = CblasNonUnit  ");
        } else if ( ( strcmp( str1, "trans"  ) == 0 ) ||
                    ( strcmp( str1, "transa" ) == 0 ) ||
                    ( strcmp( str1, "transb" ) == 0 ) ) {
-            trans = va_arg( ap, CBLAS_TRANSPOSE * );
-            if ( (int)trans == CblasNoTrans )
+            trans = va_arg( ap, CBLAS_TRANSPOSE );
+            if ( trans == CblasNoTrans )
                printf("%s = CblasNoTrans  ", str);
-            else if ( (int)trans == CblasTrans )
+            else if ( trans == CblasTrans )
                printf("%s = CblasTrans  ", str);
-            else if ( (int)trans == CblasConjTrans )
+            else if ( trans == CblasConjTrans )
                printf("%s = CblasConjTrans  ", str);
        }
     } while ( (str = strtok( NULL, seps )) != NULL );

 


Viewing all articles
Browse latest Browse all 3005

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>