what is funtion for delay in VC

L

lucifer

hi
i need to insert delay in my program what function should i use
the old delay is not supported by the VC6
 
W

Walter Roberson

i need to insert delay in my program what function should i use
the old delay is not supported by the VC6

As you posted to comp.lang.c, our answer will be in terms of
the features provided by standardized C. Anything VC6 should
be discussed in a newsgroup appropriate for VC6.

Standard C provides no delay functions at all. None. Not one.
Zero. Zippo. Null set.

The closest you can get to a delay function in C is a loop that changes
the value of a volatile variable that has external linkage.

If you looped changing a local variable, there is the risk that the
optimizer would optimize the loop out completely, but for volatile
variables it should assume that there might be -some- other
mechanism that might change the value, so it shouldn't optimize
out the loop.

This is, of course, a very crude delay mechanism, and the duration
of the delay will likely vary from run to run, and if you have
multiple calls within the same program you shouldn't expect that they
would delay by the same duration.

If you want any kind of accuracy or repeatability or calibration
of a delay duration, you will need to use some implementation-
dependant call that is outside the scope of the C standard.
 
K

Keith Thompson

lucifer said:
i need to insert delay in my program what function should i use
the old delay is not supported by the VC6

See question 19.37 in the C FAQ. It discusses delays with sub-second
resolution, but it's applicable to delays in general. Quick summary:
there's no portable way to do it, and we don't discuss non-portable
solutions here.
 
F

Flash Gordon

Walter said:
As you posted to comp.lang.c, our answer will be in terms of
the features provided by standardized C. Anything VC6 should
be discussed in a newsgroup appropriate for VC6.

Standard C provides no delay functions at all. None. Not one.
Zero. Zippo. Null set.

The closest you can get to a delay function in C is a loop that changes
the value of a volatile variable that has external linkage.

<snip>

You could also do a loop using the functions in time.h, although you
have no guarantee what precision you will get. Of course, I would not
want to use a program that made use of either of these methods so asking
in a microsoft group would indeed be the best course for the OP.
 
M

Mark McIntyre

you can use Sleep(int miliseconds) in VC++ , note the capital 'S'

There's no function of that name in C. Please don't answer offtopic
questions in CLC.
 
E

Emmanuel Delahaye

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top