Fred,
The following code compiles fine with g++ but I get the dreaded
warning: deprecated conversion from string constant to 'PCHAR {aka char*}' [-Wwrite-strings].
How would one define the struct or the assignment to remedy this?
I tried adding const to the struct
const PCHAR sNAME;
but still get the warning.
Thank you,
James
enum
{
vt_UNKNOWN,
vt_STRLIT,
vt_INTEGER,
vt_INT = vt_INTEGER,
vt_SINGLE,
vt_FLOAT = vt_SINGLE,
vt_DOUBLE,
vt_LDOUBLE,
vt_LLONG,
vt_STRVAR,
vt_DECFUNC,
vt_NUMBER,
vt_FILEPTR,
vt_UDT,
vt_STRUCT,
vt_UNION,
vt_LPSTR,
vt_BOOL,
vt_CHAR,
vt_LPSTRPTR,
vt_PCHAR,
vt_CHARPTR,
vt_VOID,
vt_LONG,
vt_WORD,
vt_DWORD,
vt_FARPROC,
vt_LPBYTE,
vt_LRESULT,
vt_BYTE,
vt_SHORT,
vt_USHORT,
vt_UINT,
vt_ULONG,
vt_ULLONG,
vt_ULONGLONG = vt_ULLONG,
vt_HWND,
vt_HDC,
vt_COLORREF,
vt_HANDLE,
vt_HINSTANCE,
vt_WNDCLASSEX,
vt_HFONT,
vt_ConsDes,
vt_VARIANT_BOOL,
vt__VARIANT_BOOL,
vt_SCODE,
vt_CY,
vt_DATE,
vt_BSTR,
vt_IUnknown,
vt_IDispatch,
vt_SAFEARRAY,
vt_PVOID,
vt_DECIMAL,
vt_DOCINFO,
vt_LOGFONT,
vt_TEXTMETRIC,
vt_WINBOOL,
vt_VARIANT
};
typedef struct _tagVVN
{
PCHAR sNAME;
int iTYPE;
int iPTRS;
}tagVVN, *LPTAGVVN;
static tagVVN atVARIANTVALUENAMES[]=
{
{"bVal",vt_BYTE,0},
{"bool",vt__VARIANT_BOOL,0},
{"boolVal",vt_VARIANT_BOOL,0},
{"bstrVal",vt_BSTR,0},
{"byref",vt_PVOID,0},
{"cVal",vt_CHAR,0},
{"cyVal",vt_CY,0},
{"date",vt_DATE,0},
{"dblVal",vt_DOUBLE,0},
{"fltVal",vt_FLOAT,0},
{"iVal",vt_SHORT,0},
{"intVal",vt_INT,0},
{"lVal",vt_LONG,0},
{"llVal",vt_LLONG,0},
{"parray",vt_SAFEARRAY,1},
{"pbVal",vt_BYTE,1},
{"pbool",vt__VARIANT_BOOL,1},
{"pboolVal",vt_VARIANT_BOOL,1},
{"pbstrVal",vt_BSTR,1},
{"pcVal",vt_CHAR,1},
{"pcyVal",vt_CY,1},
{"pdate",vt_DATE,1},
{"pdblVal",vt_DOUBLE,1},
{"pdecVal",vt_DECIMAL,1},
{"pdispVal",vt_IDispatch,1},
{"pfltVal",vt_FLOAT,1},
{"piVal",vt_SHORT,1},
{"pintVal",vt_INT,1},
{"plVal",vt_LONG,1},
{"pllVal",vt_LLONG,1},
{"pparray",vt_SAFEARRAY,2},
{"ppdispVal",vt_IDispatch,2},
{"ppunkVal",vt_IUnknown,2},
{"pscode",vt_SCODE,1},
{"puiVal",vt_USHORT,1},
{"pulVal",vt_ULONG,1},
{"pullVal",vt_ULONGLONG,1},
{"punkVal",vt_IUnknown,1},
{"pvarVal",vt_VARIANT,1},
{"scode",vt_SCODE,0},
{"uiVal",vt_USHORT,0},
{"uintVal",vt_UINT,0},
{"ulVal",vt_ULONG,0},
{"ullVal",vt_ULONGLONG,0},
{NULL,0,0}
};
Will this help ...
{(char*)"bVal",vt_BYTE,0},
in front of each string literal?
I just tested that, and it seemed to work. Before I put the (char*) before each literal in your struct array initiation I got the error too. This compiled with Code::Blocks 10.05 without errors ...
#include <cstdio>
typedef char* PCHAR;
enum
{
vt_UNKNOWN,
vt_STRLIT,
vt_INTEGER,
vt_INT = vt_INTEGER,
vt_SINGLE,
vt_FLOAT = vt_SINGLE,
vt_DOUBLE,
vt_LDOUBLE
};
typedef struct _tagVVN
{
PCHAR sNAME;
int iTYPE;
int iPTRS;
}tagVVN, *LPTAGVVN;
static tagVVN atVARIANTVALUENAMES[]=
{
{(char*)"dblVal",vt_DOUBLE,0},
{(char*)"fltVal",vt_FLOAT,0},
{(char*)"intVal",vt_INT,0}
};
int main()
{
printf("vt_UNKNOWN = %d\n",vt_UNKNOWN);
printf("vt_STRLIT = %d\n",vt_STRLIT);
printf("vt_INTEGER = %d\n",vt_INTEGER);
printf("atVARIANTVALUENAMES[0].sName = %s\n",atVARIANTVALUENAMES[0].sNAME);
getchar();
return 0;
}
I run into that one frequently. They must have added that warning in whatever mingw version is in 10.05, as it didn't do that in 10.02. Sometimes ya gotta just love C++! ;D
By the way, I got a gmail account. My email account with my ISP still works good in terms of spam. It doesn't lose any of that! >:(
Thanks Fred works fine here but......
I have 10811 warnings in 43k+ lines of c++ source.
Might take awhile :)
James
Wow, I feel for 'ya James! I've already had to fix several dozens of those. You know, there's likely some way of manipulating the warning level to turn that silly (in my mind anyway) warning off. For me, it was always easier to fix them than to investigate. But if I had thousands of them, I might rethink that!
Fred,
Oh there is a way to turn them off: -Wno-write-strings
I just started compiling bc9 as a g++ app so I could use the pcre library class code for parsing and got a bit carried away to see how many warnings there actually were. Now .... I CAN"T STOP!!!!! ;D
James
Fred,
I'm done!
It really should not have taken as long as it did. I had a brain cramp and negelected to notice a redefinition of fprintf -> 10k+ warnings.
I now have 10 warnings on 43k lines of code; all for unused variables I use for debugging.
This all started because I wanted to add properties to bc9 as I had done to Bcx8.
I began windows with VB and of course that was the way it was done. The original PBWIN did not have them as it
did not have any classes of anytype. With the new COM interface I lobbied hard for properties during the early beta.
Now that I am working with bc9/c++ I miss them.
I found an implementation that has limitations but does work rather well; just a lot of coding in c++ but not to worry as I don't code in c++! I code in bc9. :)
James
example bc9 code
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Test of Class Properties with bc9.1
'James C. Fuller Jan 1 2013
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$NOMAIN
$PROPS
$CPPHDR
$NOIO
$ONEXIT "GWGPP.BAT $FILE$ -m32 con"
$HEADER
typedef signed char SCHAR;
$HEADER
'==============================================================================
Class PropTestOne
protected:
'----------------------------------------------------------------------
'when using properties you need to prepend an "m_" to all var
'data type is "c/c++" type not bcx
'----------------------------------------------------------------------
Raw As int m_Count
Raw As long m_v1
Raw As float m_f1
Raw As stdstr m_S1
Raw m_c1 As SCHAR
public:
Raw As Integer v2
Dim Constructor PropTestOne()
'----------------------------------------------------------------------
'property declaration set up (do not use "m_" here)
'append _NOPP to use your own get/set procedures
'useful when wrapping or inheriting from other classes
'----------------------------------------------------------------------
PropGetSet Count As int
PropGetSet v1_NOPP As long
PropGetSet S1 As stdstr
PropGetSet f1 As float
PropGetSet c1 As SCHAR
End Class
'==============================================================================
'Need Constructor for property implementation
Constructor PropTestOne::PropTestOne()
End Constructor
'==============================================================================
'-----------------------------------------------------------------------
'Property setters and getters added here to cpp file
'-----------------------------------------------------------------------
'These two are for m_v1 where we have appended the _NOPP to PropGetSet
Function PropTestOne::getv1() As long
Function = m_v1
End Function
Sub PropTestOne::setv1(param As long)
m_v1 = param
End Sub
'==============================================================================
Class PropTestTwo
protected:
Raw As stdstr m_first
Raw As stdstr m_mid
Raw As stdstr m_last
Raw As stdstr m_full
public:
Dim Constructor PropTestTwo()
PropGetSet first As stdstr
PropGetSet mid As stdstr
PropGetSet last As stdstr
PropGetSet full As stdstr
End Class
'------------------------------------------------------------------------------
Constructor PropTestTwo::PropTestTwo()
End Constructor
Sub TestRef(test1 As PropTestOne &,test2 As PropTestTwo & )
Raw i As Integer
Raw j As Integer
Raw f As float
Raw c As SCHAR
Raw As __int8 c8
Raw xs As stdstr
Dim s$
'assign the value 5 to i
i = 5
'assign test's Count variable the value of i
test1.Count = i
'Print the contents of test1's Count Variable
Print test1.Count
'assign the value 8 to i
i = 8
'assign test1's Count variable the value of i again
test1.Count = i
'assign j the value of it's Count Variable
j = test1.Count
'did it work?
Print j
'Continue......
test1.Count = 327
Print test1.Count
'use v1
test1.v1 = 134567
j = test1.v1
Print j
'assign one test1 var to another
test1.v1 = test1.Count
Print test1.v1
'do a bit of addition
j = test1.v1 + test1.Count
Print j
'how about floats?
test1.f1 = 134.567
f = test1.f1
Print f
f = test1.f1 + 100.789321
Print f
'This is a public ( bad idea) variable
test1.v2 = 22
j = test1.v2
Print j
'will it work with a c++ std library string
test1.S1 = "James"
xs = test1.S1
'by adding $ bc9 thinks it's a normal bcx string
Print xs$.c_str()
test1.c1 = -88
c = test1.c1
Print c
test2.first = "James"
test2.mid = "C."
test2.last = "Fuller"
xs = (string)test2.first + " " + (string)test2.mid + " " + (string)test2.last
Print xs$.c_str()
End Sub
FUNCTION main(argc as INTEGER, argv as PCHAR ptr) as INTEGER
Raw i As Integer
Raw j As Integer
Raw f As float
Raw c As SCHAR
Raw As __int8 c8
Raw xs As stdstr
Raw test1 As PropTestOne
Raw test2 As PropTestTwo
Dim s1$,s2$
$IPRINT_OFF
TestRef(test1,test2)
Print "back from TestRef\n"
s1$ = "JAMES"
s2$ = LCASE$(s1$)
Print s1$
Print s2$
Pause
END FUNCTION
c++ code
// *********************************************************************
// Created with bc9 - BASIC To C/C++ Translator (V) 9.1.0.1 (2013/1/2)
// BCX (c) 1999 - 2009 by Kevin Diggins
// *********************************************************************
// Translated for compiling with a C++ Compiler
// On MS Windows
// *********************************************************************
// Additional lines may be needed
#if defined( __cplusplus )
#include <fstream>
#include <sstream>
#include <iomanip>
typedef std::string stdstr;
using namespace std;
#endif
//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
/* Class Property Support */
#ifndef INC_PROPERTY_HPP
#define INC_PROPERTY_HPP
#define READ_ONLY 1
#define WRITE_ONLY 2
#define READ_WRITE 3
template<typename Container, typename ValueType, int nPropType>
class property
{
public:
property()
{
m_cObject = NULL;
Set = NULL;
Get = NULL;
}
void setContainer(Container* cObject)
{
m_cObject = cObject;
}
void setter(void (Container::*pSet)(ValueType value))
{
if((nPropType == WRITE_ONLY) || (nPropType == READ_WRITE))
Set = pSet;
else
Set = NULL;
}
void getter(ValueType (Container::*pGet)())
{
if((nPropType == READ_ONLY) || (nPropType == READ_WRITE))
Get = pGet;
else
Get = NULL;
}
ValueType operator =(const ValueType& value)
{
(m_cObject->*Set)(value);
return value;
}
operator ValueType()
{
return (m_cObject->*Get)();
}
private:
Container* m_cObject;
void (Container::*Set)(ValueType value);
ValueType (Container::*Get)();
};
#endif
//=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#include <process.h> // dos
#include <conio.h> // dos
#include <direct.h> // dos
#include <io.h> // dos
#include <ctype.h> // dos/linux
#include <fcntl.h> // dos/linux
#include <math.h> // dos/linux
#include <stdio.h> // dos/linux
#include <string.h> // dos/linux
#include <stddef.h> // dos/linux
#include <stdlib.h> // dos/linux
#include <setjmp.h> // dos/linux
#include <time.h> // dos/linux
#include <stdarg.h> // dos/linux
#include <sys/types.h>
#include <sys/stat.h>
// ***************************************************
// types from winapi that may be needed
// ***************************************************
typedef char *PCHAR,*LPCH,*PCH,*NPSTR,*LPSTR,*PSTR;
typedef unsigned int UINT;
typedef unsigned long DWORD,ULONG;
typedef unsigned char UCHAR,byte;
typedef void *PVOID,*LPVOID;
//----------------------------------------------------
// this is missing From MinGWTDM64 stdlib.h
//----------------------------------------------------
#if defined(__MINGW32__) || defined(__MINGW64__)
#ifndef MAX_PATH
#define MAX_PATH 260
#endif
#endif
//----------------------------------------------------
#ifndef __cplusplus
#error A C++ compiler is required
#endif
// ***************************************************
typedef signed char SCHAR;
// *************************************************
// User's GLOBAL ENUM blocks
// *************************************************
// *************************************************
// System Defined Constants
// *************************************************
#define cSizeOfDefaultString 2048
// *************************************************
// User Defined Constants
// *************************************************
// *************************************************
// Standard Prototypes
// *************************************************
char* BCX_TmpStr(size_t,size_t= 128,int= 1);
char* lcase (const char*);
char* _strupr_(char *);
char* _strlwr_(char *);
void Pause (void);
// *************************************************
// User Defined Types And Unions
// *************************************************
class PropTestOne
{
protected:
int m_Count;
long m_v1;
float m_f1;
stdstr m_S1;
SCHAR m_c1;
public:
int v2;
PropTestOne(void);
int getCount(void);
void setCount(int);
property<PropTestOne,int,READ_WRITE> Count;
long getv1(void);
void setv1(long);
property<PropTestOne,long,READ_WRITE> v1;
stdstr getS1(void);
void setS1(stdstr);
property<PropTestOne,stdstr,READ_WRITE> S1;
float getf1(void);
void setf1(float);
property<PropTestOne,float,READ_WRITE> f1;
SCHAR getc1(void);
void setc1(SCHAR);
property<PropTestOne,SCHAR,READ_WRITE> c1;
};
class PropTestTwo
{
protected:
stdstr m_first;
stdstr m_mid;
stdstr m_last;
stdstr m_full;
public:
PropTestTwo(void);
stdstr getfirst(void);
void setfirst(stdstr);
property<PropTestTwo,stdstr,READ_WRITE> first;
stdstr getmid(void);
void setmid(stdstr);
property<PropTestTwo,stdstr,READ_WRITE> mid;
stdstr getlast(void);
void setlast(stdstr);
property<PropTestTwo,stdstr,READ_WRITE> last;
stdstr getfull(void);
void setfull(stdstr);
property<PropTestTwo,stdstr,READ_WRITE> full;
};
// *************************************************
// System Variables
// *************************************************
// *************************************************
// User Global Variables
// *************************************************
static PCHAR *g_argv;
static int g_argc;
// *************************************************
// User Prototypes
// *************************************************
void TestRef (PropTestOne &,PropTestTwo &);
int main (int,PCHAR*);
// *************************************************
// User Global Initialized Arrays
// *************************************************
// *************************************************
// Runtime Functions
// *************************************************
#ifndef BCXTmpStrSize
#define BCXTmpStrSize 2048
#endif
char *BCX_TmpStr (size_t Bites,size_t iPad,int iAlloc)
{
static int StrCnt;
static char *StrFunc[BCXTmpStrSize];
StrCnt=(StrCnt + 1) & (BCXTmpStrSize-1);
if(StrFunc[StrCnt]) {free (StrFunc[StrCnt]); StrFunc[StrCnt] = NULL;}
#if defined BCX_MAX_VAR_SIZE
if(Bites*sizeof(char)>BCX_MAX_VAR_SIZE)
{
printf("Buffer Overflow caught in BCX_TmpStr - requested space of %d EXCEEDS %d\n",(int)(Bites*sizeof(char)),BCX_MAX_VAR_SIZE);
abort();
}
#endif
if(iAlloc) StrFunc[StrCnt]=(char*)calloc(Bites+128,sizeof(char));
return StrFunc[StrCnt];
}
char *lcase (const char *S)
{
register char *strtmp = BCX_TmpStr(strlen(S),128,1);
return _strlwr_(strcpy(strtmp,(char*)S));
}
void Pause(void)
{
printf("\n%s\n","Press any key to continue . . .");
_getch();
}
char *_strupr_(char *string)
{
char *s;
if (string)
{
for(s = string; *s; ++s)
*s = toupper(*s);
}
return string;
}
char *_strlwr_(char *string)
{
char *s;
if (string)
{
for (s = string; *s; ++s)
*s = tolower(*s);
}
return string;
}
// ************************************
// User C code
// ************************************
//------------------------------------------------------------------------------
// property get/set procedures for class: PropTestOne
//------------------------------------------------------------------------------
int PropTestOne::getCount(){return m_Count;}
void PropTestOne::setCount(int param){m_Count = param;}
stdstr PropTestOne::getS1(){return m_S1;}
void PropTestOne::setS1(stdstr param){m_S1 = param;}
float PropTestOne::getf1(){return m_f1;}
void PropTestOne::setf1(float param){m_f1 = param;}
SCHAR PropTestOne::getc1(){return m_c1;}
void PropTestOne::setc1(SCHAR param){m_c1 = param;}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// property get/set procedures for class: PropTestTwo
//------------------------------------------------------------------------------
stdstr PropTestTwo::getfirst(){return m_first;}
void PropTestTwo::setfirst(stdstr param){m_first = param;}
stdstr PropTestTwo::getmid(){return m_mid;}
void PropTestTwo::setmid(stdstr param){m_mid = param;}
stdstr PropTestTwo::getlast(){return m_last;}
void PropTestTwo::setlast(stdstr param){m_last = param;}
stdstr PropTestTwo::getfull(){return m_full;}
void PropTestTwo::setfull(stdstr param){m_full = param;}
//------------------------------------------------------------------------------
// ************************************
// User Subs and Functions
// ************************************
PropTestOne::PropTestOne ()
{
Count.setContainer(this);
Count.getter( &PropTestOne::getCount);
Count.setter( &PropTestOne::setCount);
v1.setContainer(this);
v1.getter( &PropTestOne::getv1);
v1.setter( &PropTestOne::setv1);
S1.setContainer(this);
S1.getter( &PropTestOne::getS1);
S1.setter( &PropTestOne::setS1);
f1.setContainer(this);
f1.getter( &PropTestOne::getf1);
f1.setter( &PropTestOne::setf1);
c1.setContainer(this);
c1.getter( &PropTestOne::getc1);
c1.setter( &PropTestOne::setc1);
}
long PropTestOne::getv1 ()
{
return m_v1;
}
void PropTestOne::setv1 (long param)
{
m_v1= param;
}
PropTestTwo::PropTestTwo ()
{
first.setContainer(this);
first.getter( &PropTestTwo::getfirst);
first.setter( &PropTestTwo::setfirst);
mid.setContainer(this);
mid.getter( &PropTestTwo::getmid);
mid.setter( &PropTestTwo::setmid);
last.setContainer(this);
last.getter( &PropTestTwo::getlast);
last.setter( &PropTestTwo::setlast);
full.setContainer(this);
full.getter( &PropTestTwo::getfull);
full.setter( &PropTestTwo::setfull);
}
void TestRef (PropTestOne & test1,PropTestTwo & test2)
{
int i;
int j;
float f;
SCHAR c;
__int8 c8;
stdstr xs;
static char s[cSizeOfDefaultString];
i= 5;
test1.Count= i;
printf("% d\n",(int)test1.Count);
i= 8;
test1.Count= i;
j= test1.Count;
printf("% d\n",(int)j);
test1.Count= 327;
printf("% d\n",(int)test1.Count);
test1.v1= 134567;
j= test1.v1;
printf("% d\n",(int)j);
test1.v1= test1.Count;
printf("% d\n",(int)test1.v1);
j= test1.v1+ test1.Count;
printf("% d\n",(int)j);
test1.f1= 134.567;
f= test1.f1;
printf("% .7G\n",(float)f);
f= test1.f1+ 100.789321;
printf("% .7G\n",(float)f);
test1.v2= 22;
j= test1.v2;
printf("% d\n",(int)j);
test1.S1="James";
xs= test1.S1;
printf("%s\n",xs.c_str());
test1.c1=- 88;
c= test1.c1;
printf("% G\n",(float)c);
test2.first="James";
test2.mid="C.";
test2.last="Fuller";
xs=( string) test2.first+" "+( string) test2.mid+" "+( string) test2.last;
printf("%s\n",xs.c_str());
}
int main (int argc,PCHAR* argv)
{
int i;
int j;
float f;
SCHAR c;
__int8 c8;
stdstr xs;
PropTestOne test1;
PropTestTwo test2;
static char s1[cSizeOfDefaultString];
static char s2[cSizeOfDefaultString];
TestRef(test1,test2);
printf("%s\n","back from TestRef\n");
strcpy(s1,"JAMES");
strcpy(s2,lcase(s1));
printf("%s\n",s1);
printf("%s\n",s2);
Pause();
return 0;
}
Glad its working out!
VB was my first Windows programming too, back about 1996. VB4 I think. Before that all I did was DOS. I never even used Windows before that, unlike many who did 16 bit Windows.
I spent a lot of time since last weekend working with that 64 bit GNU compiler you turned me on to. I enjoyed it. I wanted to learn a little bit more about 64 bit code. I really have absolutely no need for it, nor can I even envision any need for it by myself at any point, but being a coder, I was interested to play with it.
I managed to get two interesting programs I had written up a couple years back on a command line compiling tutorial I had been working on working in both 32 bit and 64 bit versions, UNICODE or ansi, GNU or Microsoft compilers working perfectly. Same source code exactly. Think about it. That's a lot of conditional compilation, macros, #defines, and other fancy stuff! Maybe I can post that tomorrow.
Next week I gotta get back to real work!