warning C4146: unary minus operator applied to unsigned type, result still unsigned
-
Tuesday, March 10, 2009 9:34 AM
1 char* StringDump::SaveString(const char* s, int len) { 2 if (len == -1) 3 len = lstrlen(s); 4 if (block_pos+len+1 > block_size) { 5 char* newnew_block = new char[block_size = max(block_size, len+1+sizeof(char*))]; 6 _RPT0(0,"StringDump: Allocating new stringblock.\r\n"); 7 *(char**)new_block = current_block; // beginning of block holds pointer to previous block 8 current_block = new_block; 9 block_pos = sizeof(char*); 10 } 11 char* result = current_block+block_pos; 12 memcpy(result, s, len); 13 result[len] = 0; 14 block_pos += (len+sizeof(char*)) & -sizeof(char*); // Keep 32bit aligned 15 return result; 16 }
Line 14 in the code quote is the one with the warning.
warning C4146: unary minus operator applied to unsigned type, result still unsigned
All Replies
-
Tuesday, March 10, 2009 9:42 AM
-
Tuesday, March 10, 2009 9:56 AM
Select one of these:
block_pos += (len+sizeof(char*)) & -int(sizeof(char*));
or
#pragma warning( disable : 4146 )
block_pos += (len+sizeof(char*)) & -sizeof(char*);
#pragma warning( default : 4146 )
- Marked As Answer by brownie ri Tuesday, March 10, 2009 10:11 AM
-
Tuesday, March 10, 2009 10:11 AMViorel_ said:
Select one of these:
block_pos += (len+sizeof(char*)) & -int(sizeof(char*));
That worked. Thank you.

