to bug or not to bug

al.neu al.neu@softhome.net
Mon Jan 13 05:17:00 GMT 2003


Hi!

'hope i'm not bugging you...

Possible Bug...
===============

gcc -v :
========
Reading specs from c:/djgpp/lib/gcc-lib/djgpp/3.21/specs
Configured with: /devel/gnu/gcc/3.2/gnu/gcc-3.21/configure
i586-pc-msdosdjgpp --
prefix=/dev/env/DJDIR --disable-nls
Thread model: single
gcc version 3.2.1

(note DJGPP)

Bug def.
========
a function is called twice (for no apparent reason [acc. to me at least]); seems to be linked with #define.

Main Code parts (mini-program 1):
=================================
/* t.c */
#include <stdio.h>
#define max(a,b) (a > b) ? a : b

char foo(float fNumber)
{
    static int ii = 0;
    printf("ii = %i  ->  ", ii++);
    return 1;
}

int main()
{
    float faArray[2] = {1,1};
    char cChar;
    int iCount = 0;

    while (iCount < 2)
    {
        cChar = max(1,foo(faArray[iCount++]));
        printf("iCount=%i\n", iCount);
    }
    return 0;
}

/* INCORRECT output is obtained:
    output: > ii = 0  ->  ii = 1  ->  iCount=2 */

/* but the output SHOULD have been:
    output: > ii = 0  ->  iCount=1
    output: > ii = 1  ->  iCount=2 */



Can be compared to Main Code parts (mini-program 2):
====================================================
/* t2.c */
#include <stdio.h>
#define max(a,b) (a > b) ? a : b

char foo(float fNumber)
{
    static int ii = 0;
    printf("ii = %i  ->  ", ii++);
    return 1;
}

int main()
{
    float faArray[2] = {1,1};
    char cChar;
    int iCount = 0;

    while (iCount < 2)
    {
        char cTemp = foo(faArray[iCount++]);
        cChar = max(1, cTemp);
        printf("iCount=%i\n", iCount);
    }
    return 0;
}

/* CORRECT output is obtained:
    output: > ii = 0  ->  iCount=1
    output: > ii = 1  ->  iCount=2 */



/* Question:      1) is this a mistake with gcc or djgpp?
 * if not, then-  2) why are the outputs of t.c and t2.c different?
 */


Thanks
Al.

<<readme.txt, t.c, t2.c>>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20030113/fb8a37ef/attachment.htm>
-------------- next part --------------
Hi!

'hope i'm not bugging you...

Possible Bug...
===============

gcc -v :
========
Reading specs from c:/djgpp/lib/gcc-lib/djgpp/3.21/specs
Configured with: /devel/gnu/gcc/3.2/gnu/gcc-3.21/configure
i586-pc-msdosdjgpp --
prefix=/dev/env/DJDIR --disable-nls
Thread model: single
gcc version 3.2.1

(note DJGPP)

Bug def.
========
a function is called twice (for no apparent reason [acc. to me at least]); seems to be linked with #define.

Main Code parts (mini-program 1):
=================================
/* t.c */
#include <stdio.h>
#define max(a,b) (a > b) ? a : b

char foo(float fNumber)
{
    static int ii = 0;
    printf("ii = %i  ->  ", ii++);
    return 1;
}

int main()
{
    float faArray[2] = {1,1};
    char cChar;
    int iCount = 0;

    while (iCount < 2)
    {
        cChar = max(1,foo(faArray[iCount++]));
        printf("iCount=%i\n", iCount);
    }
    return 0;
}

/* INCORRECT output is obtained:
    output: > ii = 0  ->  ii = 1  ->  iCount=2 */

/* but the output SHOULD have been:
    output: > ii = 0  ->  iCount=1
    output: > ii = 1  ->  iCount=2 */



Can be compared to Main Code parts (mini-program 2):
====================================================
/* t2.c */
#include <stdio.h>
#define max(a,b) (a > b) ? a : b

char foo(float fNumber)
{
    static int ii = 0;
    printf("ii = %i  ->  ", ii++);
    return 1;
}

int main()
{
    float faArray[2] = {1,1};
    char cChar;
    int iCount = 0;

    while (iCount < 2)
    {
        char cTemp = foo(faArray[iCount++]);
        cChar = max(1, cTemp);
        printf("iCount=%i\n", iCount);
    }
    return 0;
}

/* CORRECT output is obtained:
    output: > ii = 0  ->  iCount=1
    output: > ii = 1  ->  iCount=2 */



/* Question:      1) is this a mistake with gcc or djgpp?
 * if not, then-  2) why are the outputs of t.c and t2.c different?
 */


Thanks

Al.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.c
Type: application/octet-stream
Size: 329 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20030113/fb8a37ef/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t2.c
Type: application/octet-stream
Size: 352 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-bugs/attachments/20030113/fb8a37ef/attachment-0001.obj>


More information about the Gcc-bugs mailing list