www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/03/06:51:53

Date: Mon, 3 Feb 1997 11:41:45 GMT
Message-Id: <199702031141.LAA05423@mailhost.sm.ic.ac.uk>
Mime-Version: 1.0
To: djgpp AT delorie DOT com
From: p DOT dixon AT ic DOT ac DOT uk (Paul Dixon)
Subject: Re: gcc problems

>From: "r. v. paasen" <R DOT L DOT F DOT v DOT Paasen AT stud DOT tue DOT nl>
>2)   gcc produces a warning (NOT related to 1) that I don't understand:
>     'control reaches end of non-void function `Matrix::operator ()(int,
>int) const'
>     I included the info for this warning at the end of this message.
>     Could someone explain what the warning means, and how it can be
>resolved?
>Richard.
>  float& operator()(int r, int c) const
>  {
>    #ifdef RANGECHECK
>      if (!matrix) fail("Trying to index a non-matrix"); // matrix is an
>array
>      else
>        if (r<0 || r>=rows || c<0 || c>=cols) fail("Trying to index
>matrix out of range");
>        else
>    #endif
>      return matrix[r*cols+c]; // this is line 87 with the warning
>  }

If RANGECHECK is defined then the function calls fail() - which you and I
know cannot return but which the compiler doesnt - hence if you get an error
the compiler thinks implicit return (without a value) is possible

Paul
------------------------------------------------------------------------
Paul Dixon                                   Email: p DOT dixon AT ic DOT ac DOT uk
Software Engineer                              tel:   +44 (171) 725 1098
Academic Dept of Paediatrics                   fax:   +44 (171) 725 6284
St Mary's Hospital Medical School
 (a constituent college of 
                     Imperial College of Science, Technology & Medicine)
Norfolk Place, London W2 1PG, UK
------------------------------------------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019