swprintf and GCC 2.96

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default swprintf and GCC 2.96

    Hi.

    I need to compile a C++ application that utilizes various Unicode functions,
    such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had no
    trouble compiling the code on GCC 3.2 (Red Hat 8.0) without any "special"
    compiler or linker flags. However, the same process results in a compile
    error with GCC 2.96, saying `swprintf' undeclared (first use this
    function). Here is the test code:

    /* ===== code begins ====== */

    #include <stdio.h>
    #include <wchar.h>

    int main(int argc, char *argv[])
    {
    wchar_t wcTest[21];

    swprintf(wcTest, 21, L"This is a test\n");

    return 0;
    }

    /* ===== code ends ====== */

    Here is the actual compile command. Nothing fancy.

    [dtoyama@daihard-lnx test] g++ -c test.cpp -o test.o

    Could anyone shed some light on this?

    Thanks in advance,
    Dai

    --
    Daigoro F. Toyama
    RLU #281828
    KDE 3.0.5 / RedHat 7.3 (kernel 2.4.20-13)
    Mozilla Firebird 0.6 (2003-07-21)
    Daihard Guest

  2. #2

    Default Re: swprintf and GCC 2.96

    On Wed, 23 Jul 2003 00:55:36 +0000, Daihard wrote:
    > Hi.
    >
    > I need to compile a C++ application that utilizes various Unicode functions,
    > such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had no
    > trouble compiling the code on GCC 3.2 (Red Hat 8.0) without any "special"
    [snip ... ]
    > /* ===== code begins ====== */
    Here add...

    #define _GNU_SOURCE 1
    > #include <stdio.h>
    > #include <wchar.h>
    >
    > int main(int argc, char *argv[])
    > {
    > wchar_t wcTest[21];
    >
    > swprintf(wcTest, 21, L"This is a test\n");
    >
    > return 0;
    > }
    >
    > /* ===== code ends ====== */
    >
    > Here is the actual compile command. Nothing fancy.
    >
    > [dtoyama@daihard-lnx test] g++ -c test.cpp -o test.o
    You should alwyas add -W -Wall IMO, although that doesn't do much here.

    --
    James Antill -- [email]james@and.org[/email]
    Need an efficent and powerful string library for C?
    [url]http://www.and.org/vstr/[/url]

    James Antill Guest

  3. #3

    Default Re: swprintf and GCC 2.96

    Daihard wrote:
    > I need to compile a C++ application that utilizes various Unicode
    > functions,
    > such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had no
    > trouble compiling the code on GCC 3.2 (Red Hat 8.0) without any "special"
    > compiler or linker flags. However, the same process results in a compile
    > error with GCC 2.96, saying `swprintf' undeclared (first use this
    > function). Here is the test code:
    Be aware that RedHat was the only vendor, as far as i am aware, to ship gcc
    2.96, and their doing so caused a big ruckuss in the Open Source world. The
    GNU team never released 2.96 and does not even host it on their server,
    which implies that they do not consider it to be worth releasing:
    [url]ftp://ftp.gnu.org/pub/gnu/gcc[/url]

    --
    ----- stephan beal
    Registered Linux User #71917 [url]http://counter.li.org[/url]
    I speak for myself, not my employer. Contents may
    be hot. Slippery when wet. Reading disclaimers makes
    you go blind. Writing them is worse. You have been Warned.

    stephan beal Guest

  4. #4

    Default Re: swprintf and GCC 2.96

    "James Antill" <james-netnews@and.org> wrote...
    > On Wed, 23 Jul 2003 00:55:36 +0000, Daihard wrote:
    >
    > > I need to compile a C++ application that utilizes various Unicode
    functions,
    > > such as swprintf and vswprintf, with GCC 2.96 (for Red Hat 7.3). I had
    no
    > > trouble compiling the code on GCC 3.2 (Red Hat 8.0) without any
    "special"
    >
    > Here add...
    >
    > #define _GNU_SOURCE 1
    Thanks! Worked like a charm! Just for my future reference, what does this
    macro definition do? Is this a special setting for GCC 2.96?
    > You should alwyas add -W -Wall IMO, although that doesn't do much here.
    I will look into those two flags. Again, thanks much for your help.

    Dai


    Daihard Guest

  5. #5

    Default Re: swprintf and GCC 2.96

    Michael B Allen wrote:
    >>>> Here add...
    >>>>
    >>>> #define _GNU_SOURCE 1
    >>>
    >>> Thanks! Worked like a charm! Just for my future reference, what does
    >>> this macro definition do? Is this a special setting for GCC 2.96?
    >>
    >> Peruse /usr/include/features.h
    >>
    >> As for why 2.96 needs _GNU_SOURCE, I don't know. It could be quirk, or
    >> the state of the function in various standards at the time.
    >>
    >> _GNU_SOURCE is a catchall. It seems to turn _everything_ on, but be
    >> careful, because some semantics differ between BSD, SYSV, POSIX, etc,
    >> such as w/ signal(2). Blindly defining _GNU_SOURCE may change the
    >> behavior of some things.
    >
    > I believe the preferred technique is to code to a standard. I don't
    > recall in which standard swprintf and vswprintf first appeared but they
    > are in C99 so with GCC you would might use:
    >
    > $ gcc -Wall -W -std=c99 ...
    >
    > But I have a helluva time working like that. Usually I just add prototypes
    > manually and try not to do anything obviously non-portable. These
    > functions also appear in POSIX which is easier to code to. What's the
    > GCC flag for the POSIX stadards? Anyone know where the list is? I've
    > seen it. Really.
    In <features.h>, where else?
    --
    Best Regards
    Sven
    Sven Gohlke Guest

  6. #6

    Default Re: swprintf and GCC 2.96

    Michael B Allen <mba2000@ioplex.com> wrote:
    <snip>
    > I believe the preferred technique is to code to a standard. I don't
    > recall in which standard swprintf and vswprintf first appeared but they
    > are in C99 so with GCC you would might use:
    > $ gcc -Wall -W -std=c99 ...
    > But I have a helluva time working like that. Usually I just add prototypes
    > manually and try not to do anything obviously non-portable. These
    > functions also appear in POSIX which is easier to code to. What's the
    > GCC flag for the POSIX stadards? Anyone know where the list is? I've
    > seen it. Really.
    c/o /usr/include/features.h, in Linux at least. It's not possible to have a
    POSIX command-line compiler flag, because POSIX is purely an interface.
    -std=c99 gives you variable argument macros, etc; language level stuff. I'd
    be surprised if -std=c99 _gave_ you swprintf(), as opposed to defining
    _POSIX_SOURCE or _ISOC99_SOURCE (unless swprintf() is a built-in).

    -std=c99 is similar to the -ansi flag (i.e. -std=c89 or something).
    You could still do gcc -ansi -D_POSIX_SOURCE ... etc.

    - Bill

    William Ahern Guest

  7. #7

    Default Re: swprintf and GCC 2.96

    Michael B Allen wrote:
    > $ gcc -Wall -W -std=c99 ...
    >
    > But I have a helluva time working like that. Usually I just add prototypes
    > manually and try not to do anything obviously non-portable. These
    > functions also appear in POSIX which is easier to code to. What's the
    > GCC flag for the POSIX stadards? Anyone know where the list is? I've
    > seen it. Really.
    I actually tried adding the prototype of vswprintf. That got me through the
    compilation, but the linking failed. I tried adding "-lw" assuming all the
    Unicode functions were defined there, but it did not work.

    Dai

    --
    Daigoro F. Toyama
    RLU #281828
    KDE 3.0.5 / RedHat 7.3 (kernel 2.4.20-13)
    Mozilla Firebird 0.6.1 (2003-07-26)
    Daihard Guest

  8. #8

    Default Re: swprintf and GCC 2.96

    On Mon, 28 Jul 2003 00:30:28 -0400, Daihard wrote:
    > Michael B Allen wrote:
    >
    >> $ gcc -Wall -W -std=c99 ...
    >>
    >> But I have a helluva time working like that. Usually I just add
    >> prototypes manually and try not to do anything obviously non-portable.
    >> These functions also appear in POSIX which is easier to code to. What's
    >> the GCC flag for the POSIX stadards? Anyone know where the list is?
    >> I've seen it. Really.
    >
    > I actually tried adding the prototype of vswprintf. That got me through
    > the compilation, but the linking failed. I tried adding "-lw" assuming
    > all the Unicode functions were defined there, but it did not work.
    Sounds like your libc doesn't have it. I'm using glibc-2.2.5. I
    don't know when those functions were added. Look for the prototype in
    /usr/include/wchar.h. You definately do not need to link with any lib
    for the wide character functions.

    Mike
    Michael B Allen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139