This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Regex: Will re_nsub be zero if REG_NOSUB was passed to regcomp?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]