Mail Archives: cygwin/1998/08/28/10:57:42
Mark,
> /* but this gives a segmentation violation under Cygwin*/
> strtolower("Hello You");
You should not try to write to a non-writeable string as the compiler
is allowed to place it into a non-writeable section of the object
code (or some such thing like that). That is a know C language
restriction that many programmers violate.
Also, your function strtolower() is written very non-optimal. It is
probably nearly twice as slow, if not more, as a good write of that
function. Something like:
while(*pText != NULL)
{
*pText = tolower(*pText);
pText++;
}
Thanks A Bunch! David Young; VVI-DCS
http://www.vvi.com
RE:
/*
This is a little C program which demonstrates a little problem
with CYGNUS32. This code works fine on a DigitalUnix, but breaks
under
Cygwin. I do not know if it is a cygwin problem or if it is a C
problem.
The symptom is a segmentation violation in strtolower.
The SEGVIOL is always at the tolower. I found that tolower does
not
matter, what matters is that I want to change the value of the
string
passed in.
If it is a real problem and not my bad understanding of C then it
must
have to do with the way parameters are allocated on the stack
when
calling a function. This sounds like very deep in the belly of
cygwin or
the gcc compiler.
Please mail your ideas to:
Mark DOT Koennecke AT psi DOT ch
Please mail, as I do not monitor this mailing list due to time
constraints
and my irregular use of the Cygwin tools. I almost forgot: the
version
is Cygwinb19.1 on a Windows-NT workstation 4.0 with a Pentium.
*/
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
/*--------------------------------------------------------------------
-------*/
void strtolower(char *pText)
{
int i;
char *pPtr;
assert(pText);
for(i = 0, pPtr = pText; i < strlen(pText); i++, pPtr++)
{
*pPtr = tolower(*pPtr);
}
}
/*--------------------------------------------------------------------
-*/
int main(int argc, char *argv[])
{
char pBuffer[132];
/* why does this work? */
strcpy(pBuffer,"Hello You");
strtolower(pBuffer);
/* but this gives a segmentation violation under Cygwin*/
strtolower("Hello You");
printf("Success\n");
}
-
For help on using this list (especially unsubscribing), send a
message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -