Click here to Skip to main content
14,484,540 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: Just because you can doesn't mean you should. Pin
Randor 15-Dec-19 2:13
professional Randor 15-Dec-19 2:13 
GeneralRe: Just because you can doesn't mean you should. Pin
honey the codewitch14-Dec-19 16:44
mvahoney the codewitch14-Dec-19 16:44 
GeneralRe: Just because you can doesn't mean you should. Pin
PIEBALDconsult14-Dec-19 18:47
professionalPIEBALDconsult14-Dec-19 18:47 
GeneralRe: Just because you can doesn't mean you should. Pin
honey the codewitch14-Dec-19 18:50
mvahoney the codewitch14-Dec-19 18:50 
GeneralRe: Just because you can doesn't mean you should. Pin
CPallini15-Dec-19 5:52
mveCPallini15-Dec-19 5:52 
GeneralRe: Just because you can doesn't mean you should. Pin
englebart16-Dec-19 2:42
professionalenglebart16-Dec-19 2:42 
GeneralRe: Just because you can doesn't mean you should. Pin
Member 1181677616-Dec-19 7:41
MemberMember 1181677616-Dec-19 7:41 
GeneralRe: Just because you can doesn't mean you should. Pin
rjmoses16-Dec-19 12:56
professionalrjmoses16-Dec-19 12:56 
I read the spec and it supposed to be standard across all compilers but I have lost count of how many OS and application bugs of that type I have had to chase.

As patbob pointed out, it is the pre-decrement that is worrisome. And the first couple of times I look at the code, I missed the "!".

To test this logic, I wrote a little program which (I think) simulates the original code results:

#include <stdio.h>

int testf(int rv, int a) {
    return rv;
}

int main()
{

    int value = 0;
    for (int i = 0; i < 16; i++) {
        printf("%2x = ", value);
        int a = 0;
        if (value & 8) printf("T"); else printf("F");
        if (value & 4) printf("T"); else printf("F");
        if (value & 2) printf("T"); else printf("F");
        if (value & 1) printf("T"); else printf("F");
        printf(" = ");
        if ( (value & 8) && testf((value & 4), --a) || (value & 2) && testf((value & 1), --a))
             printf("T %d", a); 
        else 
             printf("F %d", a);

        value++;
        printf("\n");
    }
    return(0);
}


The results are:

0 = FFFF = F 0
1 = FFFT = F 0
2 = FFTF = F -1
3 = FFTT = T -1
4 = FTFF = F 0
5 = FTFT = F 0
6 = FTTF = F -1
7 = FTTT = T -1
8 = TFFF = F -1
9 = TFFT = F -1
a = TFTF = F -2
b = TFTT = T -2
c = TTFF = T -1
d = TTFT = T -1
e = TTTF = T -1
f = TTTT = T -1
GeneralRe: Just because you can doesn't mean you should. Pin
Member 1181677616-Dec-19 19:19
MemberMember 1181677616-Dec-19 19:19 
GeneralRe: Just because you can doesn't mean you should. Pin
rjmoses17-Dec-19 0:09
professionalrjmoses17-Dec-19 0:09 
GeneralRe: Just because you can doesn't mean you should. Pin
Member 1181677617-Dec-19 1:56
MemberMember 1181677617-Dec-19 1:56 
GeneralRe: Just because you can doesn't mean you should. Pin
patbob16-Dec-19 12:23
Memberpatbob16-Dec-19 12:23 
GeneralRe: Just because you can doesn't mean you should. Pin
Member 916705716-Dec-19 22:28
MemberMember 916705716-Dec-19 22:28 
GeneralMore 3D Printing......well, I couldn't help it. Pin
DaveAuld14-Dec-19 5:12
professionalDaveAuld14-Dec-19 5:12 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
OriginalGriff14-Dec-19 5:17
mveOriginalGriff14-Dec-19 5:17 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
PIEBALDconsult14-Dec-19 5:38
professionalPIEBALDconsult14-Dec-19 5:38 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
Ron Anders14-Dec-19 5:47
MemberRon Anders14-Dec-19 5:47 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
honey the codewitch14-Dec-19 7:14
mvahoney the codewitch14-Dec-19 7:14 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
Nelek14-Dec-19 7:23
protectorNelek14-Dec-19 7:23 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
honey the codewitch14-Dec-19 7:24
mvahoney the codewitch14-Dec-19 7:24 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
Nelek14-Dec-19 7:26
protectorNelek14-Dec-19 7:26 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
Jörgen Andersson14-Dec-19 11:16
professionalJörgen Andersson14-Dec-19 11:16 
JokeRe: More 3D Printing......well, I couldn't help it. Pin
Daniel Pfeffer14-Dec-19 22:10
professionalDaniel Pfeffer14-Dec-19 22:10 
GeneralRe: More 3D Printing......well, I couldn't help it. Pin
DaveAuld15-Dec-19 0:35
professionalDaveAuld15-Dec-19 0:35 
GeneralDamnit - another thing dies. Pin
OriginalGriff14-Dec-19 4:20
mveOriginalGriff14-Dec-19 4:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.