Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to get Visual C++ (2015 version) to work in "char = 8 bits" mode?

How to get Visual C++ (2015 version) to work in "char = 8 bits" mode?

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialdelphidatabasehelp
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Anthony Appleyard
    wrote on last edited by
    #1

    I am trying to revive a program that I wrote in years 2001 to 2005 for my old Borland C++ 4.51 compiler. The library functions that its compiled programs called, always ran in the mode of a character = 8 bits, not 16 bits. As this program largely handles text, not numerical values, it will have to compile to run with char = 8 bytes everywhere. For example, in this section: int rundialogbox(HWND wn, HINSTANCE I, char*name, BOOL CALLBACK /*_export*/ proc(HWND db, UINT M, WPARAM S, LPARAM L)) { DLGPROC dp = MakeProcInstance((DLGPROC)proc, I); int i = DialogBox(I, name, wn, dp); FreeProcInstance(dp); return i;} I had type mismatch error of the type char* :: WCHAR*, until in menu Project / Properties I set the character mode from Unicode to Not Set; then this section compiled OK. Whereupon, the next section void diprintf(HWND db,int c,char*fmt,...){ char C[256]; vsprintf(C,fmt,(&fmt)+1); SetDlgItemText(db,c,C); }; failed with this error: 1>faces.cpp(80): error C2664: 'int vsprintf(char *const ,const char *const ,va_list)': cannot convert argument 3 from 'char **' to 'va_list' 1> faces.cpp(80): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast I replaced `char C[256];` by `WCHAR C[256];`, and compilation error still happened. Does my Visual C++ still have an 8-bit-char-mode set of library functions? If so, how to call them?

    L 1 Reply Last reply
    0
    • A Anthony Appleyard

      I am trying to revive a program that I wrote in years 2001 to 2005 for my old Borland C++ 4.51 compiler. The library functions that its compiled programs called, always ran in the mode of a character = 8 bits, not 16 bits. As this program largely handles text, not numerical values, it will have to compile to run with char = 8 bytes everywhere. For example, in this section: int rundialogbox(HWND wn, HINSTANCE I, char*name, BOOL CALLBACK /*_export*/ proc(HWND db, UINT M, WPARAM S, LPARAM L)) { DLGPROC dp = MakeProcInstance((DLGPROC)proc, I); int i = DialogBox(I, name, wn, dp); FreeProcInstance(dp); return i;} I had type mismatch error of the type char* :: WCHAR*, until in menu Project / Properties I set the character mode from Unicode to Not Set; then this section compiled OK. Whereupon, the next section void diprintf(HWND db,int c,char*fmt,...){ char C[256]; vsprintf(C,fmt,(&fmt)+1); SetDlgItemText(db,c,C); }; failed with this error: 1>faces.cpp(80): error C2664: 'int vsprintf(char *const ,const char *const ,va_list)': cannot convert argument 3 from 'char **' to 'va_list' 1> faces.cpp(80): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast I replaced `char C[256];` by `WCHAR C[256];`, and compilation error still happened. Does my Visual C++ still have an 8-bit-char-mode set of library functions? If so, how to call them?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Anthony Appleyard wrote:

      Does my Visual C++ still have an 8-bit-char-mode set of library functions? If so, how to call them?

      The "Not Set" should allow the project to use the ANSI functions. You've already made the correct change.

      Anthony Appleyard wrote:

      void diprintf(HWND db,int c,char*fmt,...)
      {
      char C[256];
      vsprintf(C,fmt,(&fmt)+1);
      SetDlgItemText(db,c,C);
      };

      failed with this error: 1>faces.cpp(80): error C2664: 'int vsprintf(char *const ,const char *const ,va_list)': cannot convert argument 3 from 'char **' to 'va_list' 1> faces.cpp(80): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

      The debugger error tells you exactly what the problem is. The third argument needs to be a va_list. Those old unsafe typecasts are no longer legal. You can probably fix it with something like:

      void diprintf(HWND db,int c,char*fmt,...)
      {
      char C[256];
      va_list arg_ptr;
      va_start(arg_ptr, fmt);
      vsprintf(C,fmt,arg_ptr);
      SetDlgItemText(db,c,C);
      };

      The function looks unsafe. The function will overflow if the variable-argument list results in a string longer than 256 char. You should consider using the safer [vsprintf_s](https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx).

      vsprintf_s(C,256,fmt,arg_ptr);

      Best Wishes, -David Delaune

      A 1 Reply Last reply
      0
      • L Lost User

        Anthony Appleyard wrote:

        Does my Visual C++ still have an 8-bit-char-mode set of library functions? If so, how to call them?

        The "Not Set" should allow the project to use the ANSI functions. You've already made the correct change.

        Anthony Appleyard wrote:

        void diprintf(HWND db,int c,char*fmt,...)
        {
        char C[256];
        vsprintf(C,fmt,(&fmt)+1);
        SetDlgItemText(db,c,C);
        };

        failed with this error: 1>faces.cpp(80): error C2664: 'int vsprintf(char *const ,const char *const ,va_list)': cannot convert argument 3 from 'char **' to 'va_list' 1> faces.cpp(80): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

        The debugger error tells you exactly what the problem is. The third argument needs to be a va_list. Those old unsafe typecasts are no longer legal. You can probably fix it with something like:

        void diprintf(HWND db,int c,char*fmt,...)
        {
        char C[256];
        va_list arg_ptr;
        va_start(arg_ptr, fmt);
        vsprintf(C,fmt,arg_ptr);
        SetDlgItemText(db,c,C);
        };

        The function looks unsafe. The function will overflow if the variable-argument list results in a string longer than 256 char. You should consider using the safer [vsprintf_s](https://msdn.microsoft.com/en-us/library/xa1a1a6z.aspx).

        vsprintf_s(C,256,fmt,arg_ptr);

        Best Wishes, -David Delaune

        A Offline
        A Offline
        Anthony Appleyard
        wrote on last edited by
        #3

        Thanks. It compiled OK. What should this become? int discanf(HWND db, int c, char*fmt, ...) { char C[256]; GetDlgItemText(db, c, C, 256); C[255] = 0; return vsscanf(C, fmt, (&fmt) + 1); }

        L 2 Replies Last reply
        0
        • A Anthony Appleyard

          Thanks. It compiled OK. What should this become? int discanf(HWND db, int c, char*fmt, ...) { char C[256]; GetDlgItemText(db, c, C, 256); C[255] = 0; return vsscanf(C, fmt, (&fmt) + 1); }

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Anthony Appleyard wrote:

          What should this become?

          Come on man, this is something that you can easily figure out. You've been a member here for over 10 years. You know the old Chinese proverb? If you give a man a fish he is hungry again in an hour. If you teach him how to catch a fish you feed him for his lifetime. You've already had your daily fish. I highly encourage you to figure it out yourself. If you get stuck feel free to come back for more fish. Best Wishes, -大衛王

          1 Reply Last reply
          0
          • A Anthony Appleyard

            Thanks. It compiled OK. What should this become? int discanf(HWND db, int c, char*fmt, ...) { char C[256]; GetDlgItemText(db, c, C, 256); C[255] = 0; return vsscanf(C, fmt, (&fmt) + 1); }

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            For a start having an int variable called c, and a char array called C is bad enough in the same module. But in the same function it is beyond ridiculous. Use proper meaningful unique names for all your variables.

            A 1 Reply Last reply
            0
            • L Lost User

              For a start having an int variable called c, and a char array called C is bad enough in the same module. But in the same function it is beyond ridiculous. Use proper meaningful unique names for all your variables.

              A Offline
              A Offline
              Anthony Appleyard
              wrote on last edited by
              #6

              Sorry. I started computer programming in the late 1960's, when computer storage was much smaller (80,000 words memory was big), under early compilers such as Atlas Autocode and Basic, and I got accustomed to one-letter and two-letter variable names. Thanks for your help.

              L 2 Replies Last reply
              0
              • A Anthony Appleyard

                Sorry. I started computer programming in the late 1960's, when computer storage was much smaller (80,000 words memory was big), under early compilers such as Atlas Autocode and Basic, and I got accustomed to one-letter and two-letter variable names. Thanks for your help.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Anthony Appleyard wrote:

                I got accustomed to one-letter and two-letter variable names.

                I confirmed that it compiles in Visual Studio 2017. I am calling it "C Notation" naming convention.

                \#define C 256
                int Ƈ(HWND č, int c, char* Ç, ...)
                {
                char ₵[C];
                va_list Ĉ;
                va_start(Ĉ, Ç);
                GetDlgItemText(č, c, ₵, C);
                ₵[C] = 0;
                return vsscanf(₵, Ç, Ĉ);
                }

                If you use this... your coworkers will pick you up and throw you out of the office. :-D Best Wishes, -David Delaune

                L 1 Reply Last reply
                0
                • A Anthony Appleyard

                  Sorry. I started computer programming in the late 1960's, when computer storage was much smaller (80,000 words memory was big), under early compilers such as Atlas Autocode and Basic, and I got accustomed to one-letter and two-letter variable names. Thanks for your help.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I started in 1966 and the only time I used single letter names was when coding in Fortran IV.

                  1 Reply Last reply
                  0
                  • L Lost User

                    Anthony Appleyard wrote:

                    I got accustomed to one-letter and two-letter variable names.

                    I confirmed that it compiles in Visual Studio 2017. I am calling it "C Notation" naming convention.

                    \#define C 256
                    int Ƈ(HWND č, int c, char* Ç, ...)
                    {
                    char ₵[C];
                    va_list Ĉ;
                    va_start(Ĉ, Ç);
                    GetDlgItemText(č, c, ₵, C);
                    ₵[C] = 0;
                    return vsscanf(₵, Ç, Ĉ);
                    }

                    If you use this... your coworkers will pick you up and throw you out of the office. :-D Best Wishes, -David Delaune

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    There is something truly sublime about that code. :)

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups