Hi,
is the sprintf() implemetation OS specific or ANSI standard?
for eg. in a code like sprintf(variable,"%s%s",str1,str2);
in windows OS using VC++, if in case i pass NULL in str1 no problem,
the
first %s would be "". is there possibility that passing NULL would
result in core dump.
awaiting your replies.
thanks,
hari 4 3626
hari <hp******@yahoo.com> scribbled the following: Hi,
is the sprintf() implemetation OS specific or ANSI standard?
The behaviour is ANSI standard. Any specific implementation is required
to match the behaviour but otherwise it's OS specific.
for eg. in a code like sprintf(variable,"%s%s",str1,str2);
in windows OS using VC++, if in case i pass NULL in str1 no problem, the first %s would be "". is there possibility that passing NULL would result in core dump.
Yes there is a possibility. The behaviour of sprintf()'s "%s"
specifier is undefined with a NULL parameter. Windows VC++ is simply
pampering you.
awaiting your replies.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"Insanity is to be shared."
- Tailgunner
"hari" <hp******@yahoo.com> wrote in message is the sprintf() implemetation OS specific or ANSI standard? for eg. in a code like sprintf(variable,"%s%s",str1,str2);
The %p format is OS-specific. Beyond that, sprintf() can be written
portably. However it is such a commonly used function that most vendors
would think it worth their while optimising it, so the internals will
probably vary from platform to platform.
Malcolm <ma*****@55bank.freeserve.co.uk> wrote: "hari" <hp******@yahoo.com> wrote in message is the sprintf() implemetation OS specific or ANSI standard? for eg. in a code like sprintf(variable,"%s%s",str1,str2);
The %p format is OS-specific. Beyond that, sprintf() can be written portably. However it is such a commonly used function that most vendors would think it worth their while optimising it, so the internals will probably vary from platform to platform.
It is certainly not trivial to write the floating point conversion
routines in portable standard C.
- Kevin.
Thanks for the info.
Emmanuel Delahaye <em**********@noos.fr> wrote in message news:<Xn***************************@130.133.1.4>.. . In 'comp.lang.c', hp******@yahoo.com (hari) wrote:
is the sprintf() implemetation OS specific or ANSI standard? for eg. in a code like sprintf(variable,"%s%s",str1,str2);
Like any standard function, the specification of sprintf() is standard, but obviously, it's implementation is not. What is not defined by the standard can be defined by an implementation, but don't rely on it because it's not portable, and will bite you the day you change your implementation (such a thing occurs more often than you think).
in windows OS using VC++, if in case i pass NULL in str1 no problem,
Don't do that. The behaviour is undefined (aka UB). It's a bug. Always.
the first %s would be "". is there possibility that passing NULL would result in core dump.
Yes. Anything can happen with a UB. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Brian Gardels |
last post by:
Does sprintf() have the ability to concatenate or append to a buffer?
Also, does it have any format specifiers for inserting the comma for
thousands separator (12,345 rather than 12345)?
...
|
by: huey_jiang |
last post by:
Hi All,
I am trying to figure out a right syntax to convert an integer array
into hex array. sprintf worked for me on doing single integer:
int i, Iarray, n=15;
char buf;
sprintf(buf,...
|
by: steve |
last post by:
Well I've been working all morning and have finally found the source of
my "bus error (signal 10)" errors. The source is odd. The error
occurs in any function where I make the function call:
...
|
by: jimjim |
last post by:
Hello,
I was wondering about the implications of giving as an argument to sprintf a
different data type from the one specified in the format argument. This type
of question along with some...
|
by: Carson |
last post by:
Is it possible to remove the dashes in a social security number using
sprintf? If so what would the syntax look like? If sprintf won't do
this is there a C function that will?
|
by: Henryk |
last post by:
Hey there,
I have some problems with the following code snippet on a Virtex-4
PowerPC with a GCC based compiler
char chData;
sprintf(&chData, "%+05.0f", -0.038f); --I get "-000" ???...
|
by: gyan |
last post by:
Hi All,
I am using sprintf and getting starnge output in following case
char temp_rn;
memset(temp_rn,'\0',12);
sprintf(temp_rn,"0%s",temp_rn);
the final value in temp_rn is 00
how it...
|
by: Ron Ford |
last post by:
I'm looking for a freeware c99 compiler for windows. I had intended to use
MS's Visual C++ Express and use its C capability. In the past with my MS
products, I've simply needed to make .c the...
|
by: A.Leopold |
last post by:
hello,
is there a c++ equivalent function to the c-function 'sprintf'?
Thank you,
leo
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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: 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...
|
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...
|
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...
| |