Timer

Discussion in 'C++' started by Gaijinco, Apr 26, 2006.

  1. Gaijinco

    Gaijinco Guest

    How can I write a program to be executed for a given ammount of time.

    I mean I want to write a program that once started it doesn't do
    anything for like 2 minutes and then exits.

    It is possible?
    Gaijinco, Apr 26, 2006
    #1
    1. Advertising

  2. Gaijinco wrote:
    > How can I write a program to be executed for a given ammount of time.
    >
    > I mean I want to write a program that once started it doesn't do
    > anything for like 2 minutes and then exits.
    >
    > It is possible?


    It is possible if it's possible in the OS you're using. You need to see
    what "sleep" functionality your OS provides. Ask in the newsgroup
    dedicated to your OS.

    In C or C++ "doesn't do anything" is impossible. The only "delay" you
    can implement using standard means of either language is in line with

    /* take time reading, use 'time' */
    for (;;)
    {
    /* take another time reading */
    /* check if time isn't over, use 'difftime' */
    /* if it's over, break; */
    }

    but it definitely does not qualify as "doing nothing".

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Apr 26, 2006
    #2
    1. Advertising

  3. Gaijinco

    Guest

    Gaijinco wrote:
    > How can I write a program to be executed for a given ammount of time.
    >
    > I mean I want to write a program that once started it doesn't do
    > anything for like 2 minutes and then exits.
    >
    > It is possible?


    Hi I am new here. If you are programming with window platform. you can
    used Sleep function from the windows.h heander. Which look something
    like this:

    #include <iostream>
    #include <windows.h>

    int main()
    {
    std::cout << "Timer started! \n";
    Sleep(120000);
    std:;cout << "2 Minutes is over! \n"
    }

    Sleep will pause the whole program. Sleep(1000) mean pause for 1
    second, Sleep(1) mean pause for 1milli-second.

    I hope this information might help you.

    From
    Visal .In
    , Apr 26, 2006
    #3
  4. Gaijinco

    Vladimir Oka Guest

    Gaijinco wrote:
    > How can I write a program to be executed for a given ammount of time.
    >
    > I mean I want to write a program that once started it doesn't do
    > anything for like 2 minutes and then exits.
    >
    > It is possible?


    Maybe. Depends on your exact requirements. Standard C has <time.h>
    header which shoudl contain stuff you'd need. Look it up, but beware:
    not many things are guaranteed. The stuff you'd likely need is:

    CLOCKS_PER_SEC

    and

    clock_t clock(void);

    which returns the number of clock cycles since the start of your
    program. Divide by CLOCKS_PER_SEC to get to the seconds. The function
    returns `(clock_t)(-1)` if the information is not available or can't be
    represented.

    Of course, if you don't care about portability, you can always use
    whatever's available and specific to your platform. You should ask
    about these in an appropriate group (this one not being appropriate for
    platform specific questions).
    Vladimir Oka, Apr 26, 2006
    #4
  5. Gaijinco

    Vladimir Oka Guest

    wrote:
    > Gaijinco wrote:
    > > How can I write a program to be executed for a given ammount of time.
    > >
    > > I mean I want to write a program that once started it doesn't do
    > > anything for like 2 minutes and then exits.
    > >
    > > It is possible?

    >
    > Hi I am new here. If you are programming with window platform. you can
    > used Sleep function from the windows.h heander. Which look something
    > like this:
    >
    > #include <iostream>


    >From this point on, it belongs to comp.lang.c++ (although I guess

    platform specific stuff is off-topic there as well).

    Followups-to set...

    > #include <windows.h>
    >
    > int main()
    > {
    > std::cout << "Timer started! \n";
    > Sleep(120000);
    > std:;cout << "2 Minutes is over! \n"
    > }
    >
    > Sleep will pause the whole program. Sleep(1000) mean pause for 1
    > second, Sleep(1) mean pause for 1milli-second.
    >
    > I hope this information might help you.
    >
    > From
    > Visal .In
    Vladimir Oka, Apr 26, 2006
    #5
  6. Gaijinco

    CBFalconer Guest

    Gaijinco wrote:
    >
    > How can I write a program to be executed for a given ammount of time.
    >
    > I mean I want to write a program that once started it doesn't do
    > anything for like 2 minutes and then exits.
    >
    > It is possible?


    Invoke the 'as if' rule from the standard. Do nothing. Stare at
    the terminal for two minutes, then repeat doing nothing. QED.
    Very economical and environmentally friendly.

    --
    "If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers." - Keith Thompson
    More details at: <http://cfaj.freeshell.org/google/>
    Also see <http://www.safalra.com/special/googlegroupsreply/>
    CBFalconer, Apr 26, 2006
    #6
  7. "Vladimir Oka" <> writes:
    > Gaijinco wrote:
    >> How can I write a program to be executed for a given ammount of time.
    >>
    >> I mean I want to write a program that once started it doesn't do
    >> anything for like 2 minutes and then exits.
    >>
    >> It is possible?

    >
    > Maybe. Depends on your exact requirements. Standard C has <time.h>
    > header which shoudl contain stuff you'd need. Look it up, but beware:
    > not many things are guaranteed. The stuff you'd likely need is:
    >
    > CLOCKS_PER_SEC
    >
    > and
    >
    > clock_t clock(void);
    >
    > which returns the number of clock cycles since the start of your
    > program. Divide by CLOCKS_PER_SEC to get to the seconds. The function
    > returns `(clock_t)(-1)` if the information is not available or can't be
    > represented.


    <time.h> doesn't provide a function that sleeps for a specified amount
    of time. You could write a busy loop that runs until the current time
    reaches a specified value, but that's a really bad idea on a
    multi-processing system; while it's looping, your program will consume
    CPU time at the expense of other processes on the system.

    The clock() function returns an indication of the amount of CPU time
    your program has consumed; it doesn't indicate real time.

    > Of course, if you don't care about portability, you can always use
    > whatever's available and specific to your platform. You should ask
    > about these in an appropriate group (this one not being appropriate for
    > platform specific questions).


    Sleeping for a specified number of seconds is one of those things that
    can be done much better using non-portable code. Most systems will
    provide something like a sleep() function.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Apr 26, 2006
    #7
  8. Gaijinco

    siska Guest

    Keith Thompson wrote:
    > "Vladimir Oka" <> writes:
    > > Gaijinco wrote:
    > >> How can I write a program to be executed for a given ammount of time.
    > >>
    > >> I mean I want to write a program that once started it doesn't do
    > >> anything for like 2 minutes and then exits.
    > >>
    > >> It is possible?

    > >
    > > Maybe. Depends on your exact requirements. Standard C has <time.h>
    > > header which shoudl contain stuff you'd need. Look it up, but beware:
    > > not many things are guaranteed. The stuff you'd likely need is:
    > >
    > > CLOCKS_PER_SEC
    > >
    > > and
    > >
    > > clock_t clock(void);
    > >
    > > which returns the number of clock cycles since the start of your
    > > program. Divide by CLOCKS_PER_SEC to get to the seconds. The function
    > > returns `(clock_t)(-1)` if the information is not available or can't be
    > > represented.

    >
    > <time.h> doesn't provide a function that sleeps for a specified amount
    > of time. You could write a busy loop that runs until the current time
    > reaches a specified value, but that's a really bad idea on a
    > multi-processing system; while it's looping, your program will consume
    > CPU time at the expense of other processes on the system.
    >
    > The clock() function returns an indication of the amount of CPU time
    > your program has consumed; it doesn't indicate real time.
    >
    > > Of course, if you don't care about portability, you can always use
    > > whatever's available and specific to your platform. You should ask
    > > about these in an appropriate group (this one not being appropriate for
    > > platform specific questions).

    >
    > Sleeping for a specified number of seconds is one of those things that
    > can be done much better using non-portable code. Most systems will
    > provide something like a sleep() function.
    >
    > --
    > Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    > San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    > We must do something. This is something. Therefore, we must do this.


    I use this sometimes when writing short programs for
    AIX/HPUX/Linux/Solaris and Windows, I define "WIN32" when compiling on
    Windows (cl ... /D"WIN32 ..."):

    ***CODE EXAMPLE***

    /* file to include - in whatever file it is needed */
    #ifdef WIN32
    #include <windows.h>
    #else /* WIN32 */
    #include <unistd.h>
    #endif /* WIN32 */

    ....

    /* define the function to use */
    #ifdef WIN32
    #define SLEEP_TIME 5000
    #define SLEEP_FUNC Sleep
    #else /* WIN32 */
    #define SLEEP_TIME 5
    #define SLEEP_FUNC sleep
    #endif /* WIN32 */

    ....

    /* someone deep in the code the function is used */
    if( wait_for_something == true )
    {
    SLEEP_FUNC ( SLEEP_TIME );
    }

    ***CODE EXAMPLE***

    Of course this may not be the safest or best way to do it but it works
    for simple programs.

    Stephen W. Vickers
    siska, Apr 26, 2006
    #8
  9. "siska" <> writes:
    > Keith Thompson wrote:

    [...]
    >> Sleeping for a specified number of seconds is one of those things that
    >> can be done much better using non-portable code. Most systems will
    >> provide something like a sleep() function.

    [...]

    Thank you for quoting context in spite of the Google Groups interface.

    But it's seldom necessary to quote the entire article to which you're
    replying. Please trim anything that's not relevant to your reply. In
    particular, don't quote signatures unless you're commenting on them.

    > I use this sometimes when writing short programs for
    > AIX/HPUX/Linux/Solaris and Windows, I define "WIN32" when compiling on
    > Windows (cl ... /D"WIN32 ..."):
    >
    > ***CODE EXAMPLE***
    >
    > /* file to include - in whatever file it is needed */
    > #ifdef WIN32
    > #include <windows.h>
    > #else /* WIN32 */
    > #include <unistd.h>
    > #endif /* WIN32 */
    >
    > ...
    >
    > /* define the function to use */
    > #ifdef WIN32
    > #define SLEEP_TIME 5000
    > #define SLEEP_FUNC Sleep
    > #else /* WIN32 */
    > #define SLEEP_TIME 5
    > #define SLEEP_FUNC sleep
    > #endif /* WIN32 */
    >
    > ...
    >
    > /* someone deep in the code the function is used */
    > if( wait_for_something == true )
    > {
    > SLEEP_FUNC ( SLEEP_TIME );
    > }
    >
    > ***CODE EXAMPLE***
    >
    > Of course this may not be the safest or best way to do it but it works
    > for simple programs.


    That will work (I presume) if you happen to compile your program on a
    Windows or Unix-like system. It's not portable to any other systems,
    so it's off-topic here.

    Also, why do you write

    if( wait_for_something == true )

    ? Where is the identifier "true" defined? If you're using C99, it's
    in <stdbool.h>; if you're using C++, it's keyword, but C++ is
    off-topic here in comp.lang.c. (I just noticed that this is
    cross-posted to comp.lang.c and comp.lang.c++; that's hardly ever a
    good idea.)

    If a variable represents a condition, it's far better to use it
    directly as a condition:

    if (wait_for_something)
    {
    ...
    }

    Consider what happens if wait_for_something is an int with a value
    other than 0 or 1.

    And if you think that "wait_for_something == true" is clearer than
    "wait_for_something", wouldn't "(wait_for_something == true) == true"
    be better yet?

    See section 9 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Apr 27, 2006
    #9
  10. Gaijinco

    Jim Langston Guest

    "Keith Thompson" <> wrote in message
    news:...
    > "siska" <> writes:
    >> Keith Thompson wrote:

    > And if you think that "wait_for_something == true" is clearer than
    > "wait_for_something", wouldn't "(wait_for_something == true) == true"
    > be better yet?
    >
    > See section 9 of the comp.lang.c FAQ, <http://www.c-faq.com/>.


    I treat that as preference. What is the difference between:
    if ( wait_for_something )
    and
    if ( wait_for_something == true )

    The biggest difference is that me, looking at this code, immediately know in
    the second form that wait_for_something is a boolean value. In the first
    form I don't know if it's an integer or char or perhaps even something else.
    I'm one who believe in self documenting code.

    Yes, I would probably write
    if ( wait_for_something )
    only if wait_for_something was obviously a boolean value.
    Jim Langston, Apr 27, 2006
    #10
  11. "Jim Langston" <> writes:
    > "Keith Thompson" <> wrote in message
    > news:...
    >> "siska" <> writes:
    >>> Keith Thompson wrote:

    >> And if you think that "wait_for_something == true" is clearer than
    >> "wait_for_something", wouldn't "(wait_for_something == true) == true"
    >> be better yet?
    >>
    >> See section 9 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

    >
    > I treat that as preference. What is the difference between:
    > if ( wait_for_something )
    > and
    > if ( wait_for_something == true )
    >
    > The biggest difference is that me, looking at this code, immediately know in
    > the second form that wait_for_something is a boolean value. In the first
    > form I don't know if it's an integer or char or perhaps even something else.
    > I'm one who believe in self documenting code.
    >
    > Yes, I would probably write
    > if ( wait_for_something )
    > only if wait_for_something was obviously a boolean value.


    The difference is that they don't mean the same thing.

    This:
    if (wait_for_something)
    is *not* equivalent to this:
    if (wait_for_something == true)
    It's equivalent to this:
    if (wait_for_something != 0)

    If you restrict yourself to _Bool (C99) or bool (C++), you can
    probably get away with assuming that the value will always be 0 or 1.
    But if wait_for_something is an int being used to indicate a
    condition, any non-zero value is treated as true; the is*() function
    in <ctype.h>, for example, can return any non-zero value for true.

    Note that this is cross-posted to comp.lang.c and comp.lang.c++.
    Since C++ has had a built-in bool type longer than C has, this
    argument may not be as strong for C++ as it is for C. But equality
    comparisons to true or false are still a bad idea.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Apr 27, 2006
    #11
  12. Gaijinco

    Jim Langston Guest

    "Keith Thompson" <> wrote in message
    news:...
    > "Jim Langston" <> writes:
    >> "Keith Thompson" <> wrote in message
    >> news:...
    >>> "siska" <> writes:
    >>>> Keith Thompson wrote:
    >>> And if you think that "wait_for_something == true" is clearer than
    >>> "wait_for_something", wouldn't "(wait_for_something == true) == true"
    >>> be better yet?
    >>>
    >>> See section 9 of the comp.lang.c FAQ, <http://www.c-faq.com/>.

    >>
    >> I treat that as preference. What is the difference between:
    >> if ( wait_for_something )
    >> and
    >> if ( wait_for_something == true )
    >>
    >> The biggest difference is that me, looking at this code, immediately know
    >> in
    >> the second form that wait_for_something is a boolean value. In the first
    >> form I don't know if it's an integer or char or perhaps even something
    >> else.
    >> I'm one who believe in self documenting code.
    >>
    >> Yes, I would probably write
    >> if ( wait_for_something )
    >> only if wait_for_something was obviously a boolean value.

    >
    > The difference is that they don't mean the same thing.
    >
    > This:
    > if (wait_for_something)
    > is *not* equivalent to this:
    > if (wait_for_something == true)
    > It's equivalent to this:
    > if (wait_for_something != 0)
    >
    > If you restrict yourself to _Bool (C99) or bool (C++), you can
    > probably get away with assuming that the value will always be 0 or 1.
    > But if wait_for_something is an int being used to indicate a
    > condition, any non-zero value is treated as true; the is*() function
    > in <ctype.h>, for example, can return any non-zero value for true.
    >
    > Note that this is cross-posted to comp.lang.c and comp.lang.c++.
    > Since C++ has had a built-in bool type longer than C has, this
    > argument may not be as strong for C++ as it is for C. But equality
    > comparisons to true or false are still a bad idea.


    Yes. In C I wouldn't compare against anything, since C doesn't have a true
    boolean value. I responded to this in c.l.c++ and didnt' realize it was
    cross posted.

    I *might* do if ( wait_for_something != 0 ) because of a history I've had
    with comparing integers as boolean in a language that didn't have a boolean
    and, only a bitwise and.
    Jim Langston, Apr 27, 2006
    #12
  13. Gaijinco

    Vladimir Oka Guest

    Keith Thompson opined:

    > "Vladimir Oka" <> writes:
    >> Gaijinco wrote:
    >>> How can I write a program to be executed for a given ammount of
    >>> time.
    >>>
    >>> I mean I want to write a program that once started it doesn't do
    >>> anything for like 2 minutes and then exits.
    >>>
    >>> It is possible?

    >>
    >> Maybe. Depends on your exact requirements. Standard C has <time.h>
    >> header which shoudl contain stuff you'd need. Look it up, but
    >> beware: not many things are guaranteed. The stuff you'd likely need
    >> is:
    >>
    >> CLOCKS_PER_SEC
    >>
    >> and
    >>
    >> clock_t clock(void);
    >>
    >> which returns the number of clock cycles since the start of your
    >> program. Divide by CLOCKS_PER_SEC to get to the seconds. The
    >> function returns `(clock_t)(-1)` if the information is not available
    >> or can't be represented.

    >
    > <time.h> doesn't provide a function that sleeps for a specified
    > amount of time. You could write a busy loop that runs until the
    > current time reaches a specified value, but that's a really bad idea
    > on a multi-processing system; while it's looping, your program will
    > consume CPU time at the expense of other processes on the system.
    >
    > The clock() function returns an indication of the amount of CPU time
    > your program has consumed; it doesn't indicate real time.


    OP's question was ambiguous. He asked for both "a program to be
    executed for a given amount of time", and "a program that once started
    it doesn't do anything for like 2 minutes and then exits".

    The former one is well catered for by the <time.h> and what it
    provides. The latter depends on what exactly the OP means by "doesn't
    do anything". At the assumed level OP's of experience, "sits in a
    tight loop" I though was a good guess.

    --
    "Are [Linux users] lemmings collectively jumping off of the cliff of
    reliable, well-engineered commercial software?"
    (By Matt Welsh)

    <http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>
    Vladimir Oka, Apr 27, 2006
    #13
  14. CBFalconer wrote:
    >
    > Gaijinco wrote:
    > >
    > > How can I write a program to be executed for a given ammount of time.
    > >
    > > I mean I want to write a program that once started it doesn't do
    > > anything for like 2 minutes and then exits.
    > >
    > > It is possible?

    >
    > Invoke the 'as if' rule from the standard. Do nothing. Stare at
    > the terminal for two minutes, then repeat doing nothing. QED.
    > Very economical and environmentally friendly.
    >

    Want to see my fast draw??? Want to see it again???

    --
    +----------------------------------------------------------------+
    | Charles and Francis Richmond richmond at plano dot net |
    +----------------------------------------------------------------+
    Charles Richmond, Apr 28, 2006
    #14
  15. Gaijinco

    siska Guest

    Wow I had no idea so many people cared.

    The code was just a snippet - so:

    1. I did not imply what type "wait_for_somthing" was.
    2. What the type or value of "true" was.

    This was merely an example of "if we should wait for something then
    sleep for some time" - no full program/code was given so why so many
    people take it so literally I don't know.

    For all of those who can't wait to post and make others feel like they
    know nothing - ***just chill*** I'm just trying to help other newbies
    learn the great program of "c".

    ***GIVE EVERYONE A BREAK***

    Assumptions ... assumptions, if "true" is this then blah blah blah, and
    if "true" is this then blah blah......

    Did I say it was completely portable - NO - I said:

    ***QUOTE***

    I use this sometimes when writing short programs for
    AIX/HPUX/Linux/Solaris and Windows, I define "WIN32" when compiling on
    Windows (cl ... /D"WIN32 ..."):

    ***QUOTE***

    So:

    ***QUOTE***

    That will work (I presume) if you happen to compile your program on a
    Windows or Unix-like system. It's not portable to any other systems,
    so it's off-topic here.

    ***QUOTE***

    While being true is a bit irrelevent - the part about portability that
    is. What about this:

    ***QUOTE***

    ? Where is the identifier "true" defined? If you're using C99, it's
    in <stdbool.h>; if you're using C++, it's keyword, but C++ is
    off-topic here in comp.lang.c. (I just noticed that this is
    cross-posted to comp.lang.c and comp.lang.c++; that's hardly ever a
    good idea.)

    ***QUOTE***

    Who the hell said anything about c++? If I was talking c++ I would
    have posted in the c++ forum! Just because I used "true" doesnt' meen
    I am talking c++, what if that of "true" is defined as 26?

    Steve
    siska, Apr 28, 2006
    #15
  16. Gaijinco

    Flash Gordon Guest

    siska wrote:
    > Wow I had no idea so many people cared.


    People in comp.lang.c generally care about accuracy.

    > The code was just a snippet - so:
    >
    > 1. I did not imply what type "wait_for_somthing" was.


    By naming it as you did you implied that it acts as a boolean function
    returning some indication of whether "something" has happened.

    > 2. What the type or value of "true" was.


    The implication is in it's name.

    Had you use "x == y" there would have been no implication that you were
    dealing with some form of boolean.

    > This was merely an example of "if we should wait for something then
    > sleep for some time" - no full program/code was given so why so many
    > people take it so literally I don't know.


    Why should a short snippet be allowed to have more problems than a large
    snippet or complete program?

    > For all of those who can't wait to post and make others feel like they
    > know nothing - ***just chill*** I'm just trying to help other newbies
    > learn the great program of "c".


    No, people don't want to make others think they know nothing. They want
    to help people become better programmers, and unless someone knows what
    they do wrong how will they learn not to do it?

    > ***GIVE EVERYONE A BREAK***
    >
    > Assumptions ... assumptions, if "true" is this then blah blah blah, and
    > if "true" is this then blah blah......


    What people made were very important points. People here have come
    across *real* situations where the type of code you showed was use and
    it FAILED because the author did not understand the problems.

    > Did I say it was completely portable - NO - I said:
    >
    > ***QUOTE***
    >
    > I use this sometimes when writing short programs for
    > AIX/HPUX/Linux/Solaris and Windows, I define "WIN32" when compiling on
    > Windows (cl ... /D"WIN32 ..."):
    >
    > ***QUOTE***
    >
    > So:
    >
    > ***QUOTE***
    >
    > That will work (I presume) if you happen to compile your program on a
    > Windows or Unix-like system. It's not portable to any other systems,
    > so it's off-topic here.
    >
    > ***QUOTE***
    >
    > While being true is a bit irrelevent - the part about portability that
    > is. What about this:


    No, the part about portability is COMPLETELY relevant. There is a vast
    amout of SW development done in C for systems other than Windows and *nix.

    > ***QUOTE***
    >
    > ? Where is the identifier "true" defined? If you're using C99, it's
    > in <stdbool.h>; if you're using C++, it's keyword, but C++ is
    > off-topic here in comp.lang.c. (I just noticed that this is
    > cross-posted to comp.lang.c and comp.lang.c++; that's hardly ever a

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    > good idea.)
    >
    > ***QUOTE***
    >
    > Who the hell said anything about c++? If I was talking c++ I would
    > have posted in the c++ forum!


    You *did* post in a C++ news group as is pointed out in the text you
    quoted above.

    > Just because I used "true" doesnt' meen
    > I am talking c++, what if that of "true" is defined as 26?


    Then you should let people know what it is defined as, because if it is
    26 then your SW is even worse.

    If you don't like people pointing out problems with code you post (and
    the problem you are complaining about being pointed out is a very real
    problem), then I would advise against posting code to comp.lang.c since
    one of the valuable services people provide is analysing code and
    pointing out all the problems they can in it.
    --
    Flash Gordon, living in interesting times.
    Web site - http://home.flash-gordon.me.uk/
    comp.lang.c posting guidelines and intro:
    http://clc-wiki.net/wiki/Intro_to_clc
    Flash Gordon, Apr 28, 2006
    #16
  17. "siska" <> writes:
    > Wow I had no idea so many people cared.
    >
    > The code was just a snippet - so:
    >
    > 1. I did not imply what type "wait_for_somthing" was.
    > 2. What the type or value of "true" was.


    [big snip]

    > ***QUOTE***
    >
    > ? Where is the identifier "true" defined? If you're using C99, it's
    > in <stdbool.h>; if you're using C++, it's keyword, but C++ is
    > off-topic here in comp.lang.c. (I just noticed that this is
    > cross-posted to comp.lang.c and comp.lang.c++; that's hardly ever a
    > good idea.)
    >
    > ***QUOTE***
    >
    > Who the hell said anything about c++? If I was talking c++ I would
    > have posted in the c++ forum! Just because I used "true" doesnt' meen
    > I am talking c++, what if that of "true" is defined as 26?


    It would be polite to indicate who you're quoting.

    You *did post to the c++ forum (perhaps not intentionally). Take a
    look at the Newsgroups header; this thread is cross-posted to
    comp.lang.c and comp.lang.c++. Assuming that you might be using C++
    (note that I wrote "*if* you're using C++) isn't much of a stretch.
    Even if you had posted only to comp.lang.c, it still wouldn't have
    been much of a stretch; many people (inappropriately) post C++ code to
    comp.lang.c.

    And if you're using C, defining the identifier "true" yourself is
    still a bad idea, since C99's <stdbool.h> header defines "true" as a
    macro, which expands to the integer constant 1. It won't cause any
    real problems if you use a C90 implementation, or if you don't use
    "#include <stdbool.h>", but it's still best to avoid it. If you want
    to define your own Boolean type in C90, you can do something like
    this:
    typedef enum { FALSE, TRUE } BOOL;
    or this:
    typedef int BOOL;
    #define FALSE 0
    #define FALSE 1
    See also section 9 of the comp.lang.c FAQ.

    (C++, building on the experience of C, avoided this problem by
    defining bool, false, and true as keywords from the very beginning.
    Unfortunately, making such a change in C would have broken existing
    code.)

    You posted code (possibly pseudo-code) that included the line

    if( wait_for_something == true )

    I pointed out that that's a bad idea, and explained why. I don't know
    why you seem to have a problem with that; somebody else might learn
    from it, even if you don't.

    If you post code here, people will comment on it. If don't want
    people commenting on your code, don't post it.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Apr 28, 2006
    #17
  18. Gaijinco

    siska Guest

    he he he he - you just won't let it go :)
    siska, Apr 30, 2006
    #18
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Daniel Maycock via .NET 247

    My Threading Timer Doesn't Fire

    Daniel Maycock via .NET 247, Mar 28, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    523
    steve
    Mar 30, 2005
  2. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    704
    Kelsang Wangchuk
    Jul 31, 2003
  3. Replies:
    1
    Views:
    1,579
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  4. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,186
    Bruce Barker
    Nov 4, 2005
  5. Replies:
    8
    Views:
    481
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page