473,387 Members | 1,891 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,387 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 4797
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.