fscanf and NULL

M

Mantorok Redgormor

I have failed to find an authoritive answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?

I went through J.2 of the standard but it isn't listed as
undefined behavior nor implementation defined.

Anyone know where it says what type of behavior this invokes?
 
E

E. Robert Tisdale

Mantorok said:
I have failed to find an authoritative answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?

I went through J.2 of the standard but it isn't listed as
undefined behavior nor implementation defined.

Anyone know where it says what type of behavior this invokes?

It is used to reformat your hard disk drive. :)
 
J

Jack Klein

I have failed to find an authoritive answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?

I went through J.2 of the standard but it isn't listed as
undefined behavior nor implementation defined.

Anyone know where it says what type of behavior this invokes?

<quote>
7.1.4 Use of library functions
1 Each of the following statements applies unless explicitly stated
otherwise in the detailed descriptions that follow: If an argument to
a function has an invalid value (such as a value outside the domain of
the function, or a pointer outside the address space of the program,
or a null pointer, or a pointer to non-modifiable storage when the
corresponding parameter is not const-qualified) or a type (after
promotion) not expected by a function with variable number of
arguments, the behavior is undefined.
<unquote>

Since the definition of fscanf() does not specifically state that the
first argument may be a null pointer, as for example realloc() or
strtol() do, passing one results in undefined behavior.
 
D

Dan Pop

In said:
I have failed to find an authoritive answer on the following:

fscanf(NULL, ..);

The rest of the function arguments have been omitted.

I'm only curious as to what behavior is given when
the first argument is NULL?

You don't even need the standard in order to figure out the answer:
fscanf expects a valid stream as its first argument and NULL doesn't
match this description. Undefined behaviour.

The only exception to this rule is fflush, which flushes all the streams
that can be flushed when given NULL instead of a valid stream.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top