• Re: The C Gods hate me.

    From David Taylor@3:770/3 to The Natural Philosopher on Tue Aug 8 18:45:30 2023
    On 08/08/2023 18:35, The Natural Philosopher wrote:
    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    I think I'm going to watch TV instead.

    Try changing the order in which variables are declared - perhaps you're overwriting something? Or something like that?
    --
    Cheers,
    David
    Web: https://www.satsignal.eu

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From TimS@3:770/3 to tnp@invalid.invalid on Tue Aug 8 17:54:00 2023
    On 08 Aug 2023 at 18:35:51 BST, "The Natural Philosopher"
    <tnp@invalid.invalid> wrote:

    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    I once earwigged on a conversation at CERN between a physicist and someone in the Program Enquiry Office, where users could go to get help with their programs. The physicist reported similar symptoms to you, and of course it turmned out that his conditional GOTO which was intended to skip the debugging statements, was skipping a big chunk of that particular subroutine.

    --
    Tim

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to All on Tue Aug 8 18:35:50 2023
    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    I think I'm going to watch TV instead.

    --
    "Women actually are capable of being far more than the feminists will
    let them."

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Andy Burns@3:770/3 to The Natural Philosopher on Tue Aug 8 18:43:58 2023
    The Natural Philosopher wrote:

    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    The lesser spotted heisenbug

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Ahem A Rivet's Shot@3:770/3 to The Natural Philosopher on Tue Aug 8 20:43:18 2023
    On Tue, 8 Aug 2023 18:35:51 +0100
    The Natural Philosopher <tnp@invalid.invalid> wrote:

    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    Many years ago a colleague of mine had one of those that he was
    able to pin down to a bug in the register use tracking in that particular compiler (MS supplied IIRC). In the end the production code had a call out
    to a function that did nothing just to force the compiler to behave.

    I think I'm going to watch TV instead.

    Yeah - you probably have an access beyond bounds problem - have fun finding it.

    --
    Steve O'Hara-Smith
    Odds and Ends at http://www.sohara.org/
    Host: Beautiful Theory meet Inconvenient Fact
    Obit: Beautiful Theory died today of factual inconsistency

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Dennis@3:770/3 to Ahem A Rivet's Shot on Tue Aug 8 17:10:16 2023
    On 8/8/23 14:43, Ahem A Rivet's Shot wrote:

    Yeah - you probably have an access beyond bounds problem - have fun finding it.

    Another possibility is a timing problem. Debug code can slow things down
    enough to change a race condition.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Computer Nerd Kev@3:770/3 to The Natural Philosopher on Wed Aug 9 09:00:58 2023
    The Natural Philosopher <tnp@invalid.invalid> wrote:
    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    You could also try Gdb on the version with the debugging code
    turned off. But building with Gdb support enabled can change
    program behaviour too. I found it wasn't friendly with (direct)
    GPIO operations on the Pi Zero and things only worked sensibly
    without it.

    --
    __ __
    #_ < |\| |< _#

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Jan Panteltje@3:770/3 to Philosopher on Wed Aug 9 05:41:36 2023
    On a sunny day (Tue, 8 Aug 2023 18:35:51 +0100) it happened The Natural Philosopher <tnp@invalid.invalid> wrote in <uatudn$3g3qj$3@dont-email.me>:

    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    Depends
    I never use debuggiging code whatver that is
    but every subroutine routine I write starts like this:

    int connect_to_news_server(char *server, int port)
    {
    struct hostent *hp;
    struct sockaddr_in sa; /* -Wall gets confused */
    int a, i;
    char temp[TEMP_SIZE];
    char dotted_quad[TEMP_SIZE];
    int flags;
    time_t connect_timer;
    extern int idle_cb();
    int connect_flag;
    unsigned long in;
    int byname;

    if(debug_flag)
    {
    fprintf(stdout, "connect_to_news_server(): arg server=%s port=%d\n",\
    server, port);
    }

    /* argument check */
    if(! server) return(0);
    if(port <= 0) return(0);


    So if I specify -v on the command line that sets 'debug_flag' and shows what is happening everywhere
    If I just comment out the 'if(debug_flag)' it shows what's happening with / in that specific
    routine.
    If -v specified then with any argument error it wil exit with the last routine where it failed
    Usually only takes a second to find a fault.





    I think I'm going to watch TV instead.

    Yea but no football today?


    --
    "Women actually are capable of being far more than the feminists will
    let them."




    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Pancho@3:770/3 to Jan Panteltje on Wed Aug 9 08:11:26 2023
    On 09/08/2023 06:41, Jan Panteltje wrote:
    On a sunny day (Tue, 8 Aug 2023 18:35:51 +0100) it happened The Natural Philosopher <tnp@invalid.invalid> wrote in <uatudn$3g3qj$3@dont-email.me>:

    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    Depends
    I never use debuggiging code whatver that is
    but every subroutine routine I write starts like this:

    int connect_to_news_server(char *server, int port)
    {
    struct hostent *hp;
    struct sockaddr_in sa; /* -Wall gets confused */
    int a, i;
    char temp[TEMP_SIZE];
    char dotted_quad[TEMP_SIZE];
    int flags;
    time_t connect_timer;
    extern int idle_cb();
    int connect_flag;
    unsigned long in;
    int byname;

    if(debug_flag)
    {
    fprintf(stdout, "connect_to_news_server(): arg server=%s port=%d\n",\
    server, port);
    }

    /* argument check */
    if(! server) return(0);
    if(port <= 0) return(0);


    So if I specify -v on the command line that sets 'debug_flag' and shows what is happening everywhere
    If I just comment out the 'if(debug_flag)' it shows what's happening with / in that specific
    routine.
    If -v specified then with any argument error it wil exit with the last routine where it failed
    Usually only takes a second to find a fault.


    Sorry, I should have read your post before I posted mine. I made the
    same kind of point. Diagnostics should be permanent.

    Although, what you are suggesting looks a bit like a verbose version of
    ASSERT. Which can cause problems. In general, I prefer loggers.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Pancho@3:770/3 to The Natural Philosopher on Wed Aug 9 08:03:36 2023
    On 08/08/2023 18:35, The Natural Philosopher wrote:
    Every time I add debugging code it works perfectly: every time I remove
    it, it stops working....

    I think I'm going to watch TV instead.


    I try to make debug code part of the standard build, configurable at
    runtime, e.g. loggers etc, is there a log4C? There is!

    You might still have the same problem, but at least it is easier to switch.

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Richard Kettlewell@3:770/3 to The Natural Philosopher on Wed Aug 9 15:54:58 2023
    The Natural Philosopher <tnp@invalid.invalid> writes:
    The only true bug I ran into was a precedence thing something like if(g=function(h) >0) where I forgot that assignment is a lower
    priority than comparison...

    The compiler can warn you about that one; but you do have to turn
    warnings on. -Wall -Wextra is a common minimum. I usually use -Werror as
    well to enforce that all warnings are cleaned up but that’s more of a
    matter of taste.

    $ cat t.c
    int function(int);

    int main(void) {
    int g, h = 0;
    if(g=function(h) >0)
    return 0;
    else
    return 1;
    }
    $ gcc -c t.c
    $ gcc -Wall -Wextra -c t.c
    t.c: In function ‘main’:
    t.c:5:6: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
    5 | if(g=function(h) >0)
    | ^

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Tauno Voipio@3:770/3 to The Natural Philosopher on Thu Aug 10 12:23:52 2023
    On 9.8.2023 12:41 PM, The Natural Philosopher wrote:

    int connect_to_news_server(char *server, int port)
    {
    struct hostent *hp;
    struct sockaddr_in sa; /* -Wall gets confused */
    int a, i;
    char temp[TEMP_SIZE];
    char dotted_quad[TEMP_SIZE];
    int flags;
    time_t connect_timer;
    extern int idle_cb();
    int connect_flag;
    unsigned long in;
    int byname;

    if(debug_flag)
         {
         fprintf(stdout, "connect_to_news_server(): arg server=%s
    port=%d\n",\
         server, port);
         }


    Drop the backslash from the end of thew fprintf line. It is perfectly
    allowable to have whitespace between the function arguments. Whitespace includes newlines.

    --

    -TV

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)