-
July 29th, 2017, 02:11 PM
#1
[SOLVED]: How to fix this warning?
Hi, guys,
I have following code:
Code:
int bufferSize = 1024;
SQLSMALLINT lenUsed;
for( int i = 0; i < numCols; i++ )
{
autoincrement = 0;
columnNames[i] = new SQLWCHAR[sizeof( SQLWCHAR ) * SQL_MAX_COLUMN_NAME_LEN + 1];
ret = SQLColAttribute( stmt_colattr, (SQLUSMALLINT) i + 1, SQL_DESC_LABEL, columnNames[i], bufferSize, &lenUsed, NULL );
}
Compiling this with MSVC 2010, I'm getting:
warning C4244: 'argument' : conversion from 'int' to 'SQLSMALLINT', possible loss of data
on the SQLColAttribute() call.
How do I fix the warning?
Thank you.
Last edited by OneEyeMan; August 1st, 2017 at 11:47 AM.
Reason: Marking as solved
-
July 29th, 2017, 02:21 PM
#2
Re: How to fix this warning?
You could define i as a SQLUSMALLINT, or you could just ignore it.
-
July 29th, 2017, 02:24 PM
#3
Re: How to fix this warning?
Try
Code:
SQLSMALLINT bufferSize = 1024;
as the bufferlength param to SQLColAttribute() is typed as SQLSMALLINT - not int. See https://docs.microsoft.com/en-us/sql...ibute-function
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
July 29th, 2017, 04:42 PM
#4
Re: How to fix this warning?
@2kaud:
That was it.
Thank you.
-
July 31st, 2017, 02:26 AM
#5
Re: How to fix this warning?
Or you may replace int with short...
Victor Nijegorodov
-
July 31st, 2017, 03:19 AM
#6
Re: How to fix this warning?
replacing int with short is the best way I think
-
July 31st, 2017, 03:39 AM
#7
Re: How to fix this warning?
The bufferlength parameter of function SQLColAttribute() is defined as type SQLSMALLINT. Therefore a variable of this type should be passed. Whilst currently SQLSMALLINT equates to type short - and therefore passing a variable of type short will currently also avoid the compiler warning, IMO this type equivalence shouldn't be assumed as the underlying type of SQLSMALLINT could change in future releases. Always best to use the specified type.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|