GNU regcomp(3), regexec(3): '\w'

Peter L. Peres plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org
Sat Jan 3 00:42:44 UTC 2004


On Fri, 2 Jan 2004, John Wildberger wrote:

> I compiled it with gcc on mdk9.1 and got the same result as William Park
> match={abc_}
> John

Eh ? Strange. I just recompiled with all warnings on:

plp-NSb0HxlTAbs at public.gmane.org:~/PROJECTS/REGEXP > gcc -o r r.c -Wall --pedantic
r.c:9: warning: return-type defaults to `int'
r.c: In function `main':
r.c:28: warning: implicit declaration of function `strndup'
r.c:28: warning: format argument is not a pointer (arg 3)
r.c:30: warning: control reaches end of non-void function

I attach a binary linked against libc.so.6 and ld-linux.so.2 (file r) and
the code as I copied it (file r.c). Also result of running the example
under script (s.txt). My compiler is:

plp-NSb0HxlTAbs at public.gmane.org:~/PROJECTS/REGEXP > gcc --version
2.7.2.3

Something is definitely wrong at your end. Maybe there is a character
width thing problem or alignment due to strndup not being a proper pointer
or ? -Wall shows strndup implied. strndup is in string.h but it is only
defined if __USE_GNU is defined, via features.h, using:

gcc -D_GNU_SOURCE -Wall --pedantic r.c -o r

This makes no difference here (both versions produce the same result):

plp-NSb0HxlTAbs at public.gmane.org:~/PROJECTS/REGEXP > ./r
-- test={abc_123}, match={abc_123}

Maybe on your machines pointers are 64 bits and integers 32 ?

sorry, no more ideas,

Peter
-------------- next part --------------
Script started on Sat Jan  3 02:30:04 2004
plp at plp:~/PROJECTS/REGEXP > ./r

-- test={abc_123}, match={abc_123}

plp at plp:~/PROJECTS/REGEXP > exit

exit


Script done on Sat Jan  3 02:30:10 2004
-------------- next part --------------

#include <sys/types.h>
#include <regex.h>

#include <stdio.h>
#include <string.h>

main ()
{
    regex_t preg;
	regmatch_t pmatch[1];
	int a, b;
	char *test;
	
    if (regcomp (&preg, "\\w+", REG_EXTENDED) != 0) {
	    puts ("error in regcomp()");
	    exit (1);
	}

    test = "abc_123";
	if (regexec (&preg, test, 1, pmatch, 0) != 0) {
		puts ("error in regexec()");
	    exit (2);
	}

	a = pmatch[0].rm_so;
	b = pmatch[0].rm_eo;
	printf ("-- test={%s}, match={%s}\n", test, strndup (test + a, b - a));
	regfree (&preg);
}	
				
							

-------------- next part --------------
A non-text attachment was scrubbed...
Name: r
Type: application/octet-stream
Size: 4890 bytes
Desc: r
URL: <http://gtalug.org/pipermail/legacy/attachments/20040103/7cbd49cc/attachment.obj>


More information about the Legacy mailing list