c - iterating over const matrix and vector -


i have function constant matrix , vector input, , trying iterate on columns follows

void matx_mut(const int *a, const int **b, unsigned int c, unsigned int a_col_start, unsigned int a_col_end,     unsigned int a_row_start, unsigned int a_row_end) {         unsigned int         int  *a_ptr, *b_ptr;         // initial processing          for( = a_col_start; <= a_col_end; i++)         {             // code               a_ptr = &a[a_col_start];             b_ptr = &b[i][a_row_start];              // more code           } }  

however, getting following warning "warning c4090: '=' : different 'const' qualifiers" . can't change a_ptr , b_ptr const because changing value on every iteration, right?

is there nice way resolve warning?, beside declaring both pointers inside 2nd loop.

i tried using initial pointers , b, made not easy read :(

as per description of c4090 warning,

a variable used in operation defined specified modifier prevents being modified without detection compiler. expression compiled without modification.

this warning can caused when pointer const or volatile item assigned pointer not declared pointing const or volatile.

reason: in code

 a_ptr = &a[a_col_start];  b_ptr = &b[i][a_row_start]; 

the target pointers non-const, source pointers are. in case, if try modify value of (through) a_ptr, according standard, chapter §6.7.3

if attempt made modify object defined const-qualified type through use of lvalue non-const-qualified type, behavior undefined.. [...]

you'll face undefined behavior. so, compiler warning potential ub might face later due modification of values through non-const pointers.

the point here is, warning there reason, try solve possible issue, don't try suppress it.

also, think, you're missing understanding of const type qualifier. in case of definition like

 const int * a_ptr; 

a_ptr not constant, *a_ptr is. so, can make a_ptr , b_ptr pointers const , assign them values inside loop. per const property, cannot change value @ location pointed pointer.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -