[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

C Compiler/Linker Warnings Involving Math function & Pointer Arithmetic


I'm receiving a couple warnings and an error that I can't figure out.  First here's the code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <mpc.h>

double *A;
double *Q;
double *R;
double *Norm;
int i,j,rows,cols,a,b,c,d,e,f,temp, mn;
FILE *file;

#define FNAME "test"

int main()
      file = fopen(FNAME, "r");

      temp = 0.0;

      A = (double *)malloc(rows*cols*sizeof(double));
      Q = (double *)malloc(rows*cols*sizeof(double));
      R = (double *)malloc(rows*cols*sizeof(double));
      Norm = (double *)malloc(cols*sizeof(double));

      if (A==NULL || Q==NULL || R==NULL)
            fprintf(stderr, "malloc failed\n");
      mn = rows*cols;
      for (i=0;i<mn;i++)
      for (a=0;a<cols;a++)
            for (b=0;b<rows;b++)
                  Norm[a] += pow(*(A+a*rows+b),2.0);
            Norm[a] = sqrt(Norm[a]);
            for (c=0;c<rows;c++)
                  *(Q+a*rows+c) = (1/Norm[a]) * (*(A+a*rows+c));
            *(R+a*rows+a) = Norm[a];
            for (d=a;d<cols-1;d++)
                  temp = 0.0;
                  for (e=0;e<rows;e++)
                        temp += *(A+(d+1)*rows+e) * *(Q+a*rows+e);

                  temp = 0.0;
                  for (f=0;f<rows;f++)
                        *(A+(d+1)*rows+f) = *(A+(d+1)*rows+f) - (*(Q+a*rows+f) * *(R+(d+1)*rows+a));


It's a sequential QR factorization of a given matrix.  Here are the warnings/errors:

cc-1171 cc: WARNING File = QR.c, Line = 64
 The indicated expression has no effect.


cc-1001 cc: WARNING File = QR.c, Line = 97
  The source file does not end with a new-line character.


        cc -64 -mp  -o QR QR.o
ld64: ERROR   33 : Unresolved text symbol "pow" -- 1st referenced by QR.o.
        Use linker option -v to see when and which objects, archives and dsos are loaded.  

So, I can't figure out why the pointer arithmetic involved with the R would have no effect, or for that matter, what that means.  Similar confusion with the new-line character at the end of the source file.  Finally, the linker doesn't appear to be able to find the power function in math.h called 'pow', although it has no problem with 'sqrt'.  

Does anyone have any experience with the above in any form?

  • 2
  • 2
1 Solution
The indicated expression has no effect.

After calculating the value of this expression, you do nothing with it, so nothing has been accomplished by that calculation.
Did you want some effect to occur here?
cdromesAuthor Commented:

Naturally, I caught this after I posted the question.  It's supposed to be

*(R+(d+1)*rows+a) = temp;

I've got the code working the way it needs to, however, I was required to take out the 'pow' and explicitly multiply the number by itself in order to square it.  I still don't understand why 'pow' doesn't work.

Also, I'm still getting the warning regarding the new line character in the source file.  Any ideas on either issue?
try adding a newline at the end of the program and compiling with -lm
cdromesAuthor Commented:
Added a new line and inserted the flag in the compile statement, still no luck.  No big deal, though.  Like I said...the program works like a champ.  I'll suck up the warning.

Thanks for your help.
The -lm is a gcc compiler flag to link to the math library.

Depending on the compiler you use, you might need to use a different way to link to the math library.

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now