home *** CD-ROM | disk | FTP | other *** search
- Q29850 Bad Code Generation with Call to Function
- C Compiler
- 5.00 5.10
- MS-DOS
-
- Problem:
- The compiler generates incorrect code for a call to the function
- strcpy() in the following program when it is compiled in small or
- medium model. When the compiler makes the following call:
-
- strcpy(macronames[nrmacros],line);
-
- the generated code pushes macrobuffer+totalmac instead of pushing
- macronames[nrmacros]. The example follows:
-
- #include <stdio.h>
- #include <string.h>
-
- int nrmacros=0;
- char macrobuffer[800],*macronames[10];
- int l;
- void openfiles()
- {
- char line[128];
- int totalmac;
- char *macropointer =macrobuffer;
- macropointer=macrobuffer+totalmac;
- macronames[nrmacros]=macropointer;
- totalmac += l-1;
- if(totalmac<=800)
- strcpy(macronames[nrmacros],line);
- }
-
- Response:
- The code that is generated is seeing the following:
-
- macronames[nrmacros] = macropointer=macrobuffer+totalmac;
-
- However, by the time the call to strcpy() is made, this equivalence
- is no longer true because the value of the variable totalmac has
- changed. You can work around the problem by making the call to strcpy
- as follows:
-
- strcpy(macropointer,line);
-
- Microsoft is researching this problem and will post new information
- as it becomes available.
-
- Keywords: buglist5.00 buglist5.10 TAR76363
- Updated 88/07/21 03:19
-