mc -> do (wy)znawcow C ;)
Wojtek Slusarczyk
wojtek w SHADOW.EU.ORG
Pią, 2 Paź 1998, 12:02:26 CEST
Hej,
W "Polnocnym Komandorze" jest sobie src/mountlist.c w ktorym w
linni 105 stoi:
char *strstr (const char *haystack, const char *needle);
/* void error (void); FIXME -- needed? */
Podczas kompilacji na glibcu pluje takim bledem :
mountlist.c:105: parse error before `__extension__'
mountlist.c:105: parse error before `needle'
mountlist.c:105: initializer element is not constant
mountlist.c:105: warning: data definition has no type or storage class
mountlist.c:105: parse error before `needle'
mountlist.c:105: warning: data definition has no type or storage class
mountlist.c:105: parse error before `size_t'
make: *** [mountlist.o] Error 1
Zagladamy do <string.h> i widzimy:
/* Find the first occurrence of NEEDLE in HAYSTACK. */
extern char *strstr __P ((__const char *__haystack, __const char *__needle));
#ifdef __USE_GNU
/* Similar to `strstr' but this function ignores the case of both strings. */
extern char *__strcasestr __P ((__const char *__haystack,
__const char *__needle));
extern char *strcasestr __P ((__const char *__haystack,
__const char *__needle));
#endif
Co wiecej w <bits/string.h> stoi:
/* Find the first occurrence of NEEDLE in HAYSTACK. */
#define _HAVE_STRING_ARCH_strstr 1
#define strstr(haystack, needle) \
(__extension__ (__builtin_constant_p (needle) && sizeof ((needle)[0]) == 1 \
? ((needle)[0] == '\0' \
? haystack \
: ((needle)[1] == '\0' \
? strchr (haystack, (needle)[0]) \
: __strstr_cg (haystack, needle, strlen (needle)))) \
: __strstr_g (haystack, needle)))
/* Please note that this function need not handle NEEDLEs with a
length shorter than two. */
__STRING_INLINE char *
__strstr_cg (__const char *__haystack, __const char __needle[],
size_t __needle_len)
{
register unsigned long int __d0, __d1, __d2;
register char *__res;
__asm__ __volatile__
("cld\n" \
"1:\n\t"
"movl %6,%%edi\n\t"
"movl %5,%%eax\n\t"
"movl %4,%%ecx\n\t"
"repe; cmpsb\n\t"
"je 2f\n\t"
"cmpb $0,-1(%%esi)\n\t"
"leal 1(%%eax),%5\n\t"
"jne 1b\n\t"
"xorl %%eax,%%eax\n"
"2:"
: "=a" (__res), "=&S" (__d0), "=&D" (__d1), "=&c" (__d2)
: "g" (__needle_len), "1" (__haystack), "d" (__needle)
: "cc");
return __res;
}
#ifdef __PIC__
__STRING_INLINE char *
__strstr_g (__const char *__haystack, __const char *__needle)
{
register unsigned long int __d0, __d1, __d2;
register char *__res;
__asm__ __volatile__
("cld\n\t"
"repne; scasb\n\t"
"notl %%ecx\n\t"
"pushl %%ebx\n\t"
"decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
"movl %%ecx,%%ebx\n"
"1:\n\t"
"movl %%edx,%%edi\n\t"
"movl %%esi,%%eax\n\t"
"movl %%ebx,%%ecx\n\t"
"repe; cmpsb\n\t"
"je 2f\n\t" /* also works for empty string, see above */
"cmpb $0,-1(%%esi)\n\t"
"leal 1(%%eax),%%esi\n\t"
"jne 1b\n\t"
"xorl %%eax,%%eax\n"
"2:\n\t"
"popl %%ebx"
: "=a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2)
: "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle),
"d" (__needle)
: "cc");
return __res;
}
#else
__STRING_INLINE char *
__strstr_g (__const char *__haystack, __const char *__needle)
{
register unsigned long int __d0, __d1, __d2, __d3;
register char *__res;
__asm__ __volatile__
("cld\n\t"
"repne; scasb\n\t"
"notl %%ecx\n\t"
"decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
"movl %%ecx,%%edx\n"
"1:\n\t"
"movl %%ebx,%%edi\n\t"
"movl %%esi,%%eax\n\t"
"movl %%edx,%%ecx\n\t"
"repe; cmpsb\n\t"
"je 2f\n\t" /* also works for empty string, see above */
"cmpb $0,-1(%%esi)\n\t"
"leal 1(%%eax),%%esi\n\t"
"jne 1b\n\t"
"xorl %%eax,%%eax\n"
"2:"
: "=a" (__res), "=&c" (__d0), "=&S" (__d1), "=&D" (__d2), "=&d" (__d3)
: "0" (0), "1" (0xffffffff), "2" (__haystack), "3" (__needle),
"b" (__needle)
: "cc");
return __res;
}
#endif
I teraz pytanie do wszystkich GURU: jak ustawic to diabelstwo za
wylaczeniem skrajnosci ???:
#if !((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1))
char *strstr (const char *haystack, const char *needle);
#endif /* fix me fix me, please ... */
Wszelkie odpowiedzi nawet bledne mile widziane ..;)
Wojciech Slusarczyk (091)4494148
Technical University of Szczecin
PGP KeyServer pgpkeys.mit.edu
Więcej informacji o liście dyskusyjnej pld-devel-pl