473,414 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

swprintf declaration inconsistencies?

I've just noticed that the swprintf() function is declared differently in
some platforms. As far as I know, GCC declares that function as

int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...);

That definition is also present in references like:
http://www.opengroup.org/pubs/online.../swprintf.html

On the other hand, it appears that at least the compiler from Microsoft
Visual Studio 2003 declares that function as:

int swprintf(wchar_t *s, const wchar_t *format, ...);

So what gives? First of all, is this function a part of the C standards? If
so, what is the standard definition, i.e., what is the right one?
Thanks in advance?
Rui Maciel
Jul 3 '07 #1
3 4798
Rui Maciel wrote:
I've just noticed that the swprintf() function is declared differently in
some platforms. As far as I know, GCC declares that function as

int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...);

That definition is also present in references like:
http://www.opengroup.org/pubs/online.../swprintf.html

On the other hand, it appears that at least the compiler from Microsoft
Visual Studio 2003 declares that function as:

int swprintf(wchar_t *s, const wchar_t *format, ...);

So what gives? First of all, is this function a part of the C standards? If
so, what is the standard definition, i.e., what is the right one?
Thanks in advance?
Rui Maciel
The standard says:

7.24.2.3 The swprintf function

Synopsis

1 #include <wchar.h>
int swprintf(wchar_t * restrict s,size_t n,
const wchar_t * restrict format, ...);

Description
2 The swprintf function is equivalent to fwprintf, except that the
argument s specifies an array of wide characters into which the
generated output is to be written, rather than written to a stream. No
more than n wide characters are written, including a terminating null
wide character, which is always added (unless n is zero).

Returns
3 The swprintf function returns the number of wide characters written in
the array, not counting the terminating null wide character, or a
negative value if an encoding error occurred or if n or more wide
characters were requested to be written.
Jul 3 '07 #2
On Jul 3, 4:31 pm, Rui Maciel <rui.mac...@gmail.comwrote:
I've just noticed that the swprintf() function is declared differently in
some platforms. As far as I know, GCC declares that function as

int swprintf(wchar_t *s, size_t n, const wchar_t *format, ...);

That definition is also present in references like:http://www.opengroup.org/pubs/online.../swprintf.html

On the other hand, it appears that at least the compiler from Microsoft
Visual Studio 2003 declares that function as:

int swprintf(wchar_t *s, const wchar_t *format, ...);

So what gives? First of all, is this function a part of the C standards? If
so, what is the standard definition, i.e., what is the right one?
swprintf was added in Amendment 1 circa 1995, the current standard
declaration is:

#include <wchar.h>
int swprintf(wchar_t * restrict s, size_t n, const wchar_t * restrict
format, ...);

The restrict qualifiers were added in C99, the rest was the same. If
I recall correctly, implementations of swprintf already existed before
it was standardized but the size parameter was added when it became
part of the standard so that it wouldn't have the same problems that
sprintf suffered from.

Robert Gamble

Jul 3 '07 #3
jacob navia wrote:
The standard says:

7.24.2.3 The swprintf function

Synopsis

1 #include <wchar.h>
int swprintf(wchar_t * restrict s,size_t n,
const wchar_t * restrict format, ...);
<snip />

Nice. Thanks for the help, Jacob and Robert, and for replying so quickly.
Kudos!
Rui Maciel
Jul 3 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
10
by: Roger Withnell | last post by:
I seem to spend far too much of my time struggling with browser inconsistencies concerning Javascript (not to mention CSS). What do you think is the most efficient development regime, including...
10
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as...
2
by: Samuel R. Neff | last post by:
Within the past few weeks we've been getting a lot of compiler errors in two classes when no errors actually exist. The error always reports as Name '_stepResizeRelocator' is not declared. ...
1
by: ig3v10 | last post by:
Hi , i have advice on the folloing code: wchar_t* day = new wchar_t ; swprintf(day,L"%4d-%2d-%2d",yy,mm,dd); how to make sure that my 'day' didn't get string bigger then 20 chars? found:
8
by: Darren Dale | last post by:
I was just searching for some guidance on how to name packages and modules, and discovered some inconsistencies on the www.python.org. http://www.python.org/doc/essays/styleguide.html says "Module...
2
by: John Hanley | last post by:
I am getting some inconsistencies with mktime(). I allocate memory for my struct tm early in my program, and assign only *some* of the member variables. t->tm_sec=s; t->tm_min=m;...
9
by: rory | last post by:
I'm having some inconsistencies in my program that I can't seem to debug. Below is code that makes a copy of a binary file, appends a unique ID and string to the copy of the binary file and then...
10
by: RooIt | last post by:
I tried my best to use swprintf() - but I don't seem to grasp what I'm doing wrong. The following sample would print 1, instead of the length of "Hello" - 5. (There are no compiler errors or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.