C Compiler/Linker Warnings Involving Math function & Pointer Arithmetic

Posted on 2007-10-15
Last Modified: 2010-04-15

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?

Question by:cdromes
    LVL 84

    Accepted 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?

    Author Comment


    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?
    LVL 84

    Expert Comment

    try adding a newline at the end of the program and compiling with -lm

    Author Comment

    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.
    LVL 53

    Expert Comment

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    This tutorial is posted by Aaron Wojnowski, administrator at  To view more iPhone tutorials, visit This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now