This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Regex: Will re_nsub be zero if REG_NOSUB was passed to regcomp?
- From: Mark Brown <ms_brown at sbcglobal dot net>
- To: libc-help at sourceware dot org
- Date: Fri, 22 Aug 2014 09:35:42 -0500
- Subject: Re: Regex: Will re_nsub be zero if REG_NOSUB was passed to regcomp?
- Authentication-results: sourceware.org; auth=none
- References: <trinity-26e0c14b-7a9e-423b-8ec6-1cf7d9075df9-1408678255688 at 3capp-mailcom-lxa11>
On 08/21/2014 10:30 PM, frank ernest wrote:
>>> Regex: Will re_nsub be zero if REG_NOSUB was passed to regcomp?
>>
>> From a programming portability perspective, the value of re_nsub in
>> this case could be either zero or the number of subexpressions, or
>> anything in between; you've told regcomp you don't care about
>> anything but pass/fail. You should not be checking this value and
>> expecting a consistent or portable result.
>>
>> Is there a context in which having this be determinate is of
>> value?
>
> Yes, if I gave the user the ability to choose to get infomation out
> of the regex match or to save memory by not recording the information
> then I could check the value of re_nsub to determine which option was
> selected. If there is no information I thought that re_nsub might not
> ever be set, but I don't know. Currently, I'm using an ifdef, but
> it's not what I would call ideal. I could find this out and offer the
> option globally through a global variable, but I wanted to check
> about this, I'm curious.
The problem is, you cannot depend on the value. Sure, you could go into
the glibc source and find out what it would return but:
1) There's no guarantee it would not change behaviors in a future
version. glibc does not define this behavior at present.
2) Your code would be non-portable, as other C libraries may treat it
differently than glibc does.
So, I would recommend against using it under these circumstances.
--
Mark Brown
ms_brown@sbcglobal.net