This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

to bug or not to bug


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>>
 

Attachment: readme.txt
Description: Text document

Attachment: t.c
Description: Binary data

Attachment: t2.c
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]