473,503 Members | 3,715 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

naming functions and variables str*

I understand that C identifiers beginning with str are reserved for
future implementations. Do variable and function names beginning with
str in my existing code, which is for my own use only, constitute a
functional bug or a potential for undefined behaviour? Does "future
implementation" mean a formal revision of the current standard?

JS
Nov 14 '05 #1
9 1337
In article <kIU6e.983315$8l.628412@pd7tw1no>,
John Smith <JS****@mail.net> wrote:
I understand that C identifiers beginning with str are reserved for
future implementations. Do variable and function names beginning with
str in my existing code, which is for my own use only, constitute a
functional bug or a potential for undefined behaviour?


If new str* are added to the standard (possibly as an addendum
rather than a formal revision), and they happen to overlap your names,
then there is the potential that if you recompiled your code with
a compiler that had the new functions, that you could run into
symbol overlaps; that could result in anything from a compile
error for mismatched prototypes, to a refusal to link, to the
code not doing what you wanted because the wrong function was called.

The idea is future-proofing: if you avoid str* now then you
don't have to change your code later.
--
Entropy is the logarithm of probability -- Boltzmann
Nov 14 '05 #2
Walter Roberson wrote:

In article <kIU6e.983315$8l.628412@pd7tw1no>,
John Smith <JS****@mail.net> wrote:
I understand that C identifiers beginning with str are reserved for
future implementations. Do variable and function names beginning with
str in my existing code, which is for my own use only, constitute a
functional bug or a potential for undefined behaviour?


If new str* are added to the standard (possibly as an addendum
rather than a formal revision), and they happen to overlap your names,
then there is the potential that if you recompiled your code with
a compiler that had the new functions, that you could run into
symbol overlaps; that could result in anything from a compile
error for mismatched prototypes, to a refusal to link, to the
code not doing what you wanted because the wrong function was called.

The idea is future-proofing: if you avoid str* now then you
don't have to change your code later.


Function names that begin with str and a lowercase letter
are reserved.
char *str_cpy(char *s1, const char *s2);
is fine.

--
pete
Nov 14 '05 #3
Walter Roberson wrote:
John Smith <JS****@mail.net> wrote:
I understand that C identifiers beginning with str are reserved for
future implementations. Do variable and function names beginning
with str in my existing code, which is for my own use only,
constitute a functional bug or a potential for undefined behaviour?


If new str* are added to the standard (possibly as an addendum
rather than a formal revision), and they happen to overlap your
names, then there is the potential that if you recompiled your code
with a compiler that had the new functions, that you could run into
symbol overlaps; that could result in anything from a compile error
for mismatched prototypes, to a refusal to link, to the code not
doing what you wanted because the wrong function was called.

The idea is future-proofing: if you avoid str* now then you
don't have to change your code later.


It's more than that. Those names are reserved for the
implementation. So an implementor can provide a functions
strblah(...) which does whatever he wishes, place it in the
library, and call it from his internal operations. If you replace
it you can cause well known standard library functions to fail.
You gotta know the territory.

I will concede in advance that such an event is unlikely, and would
probably result in negative comments about the implementation
quality.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #4
CBFalconer <cb********@yahoo.com> writes:
Walter Roberson wrote:
The idea is future-proofing: if you avoid str* now then you
don't have to change your code later.


It's more than that. Those names are reserved for the
implementation. So an implementor can provide a functions
strblah(...) which does whatever he wishes, place it in the
library, and call it from his internal operations. If you replace
it you can cause well known standard library functions to fail.
You gotta know the territory.

I will concede in advance that such an event is unlikely, and would
probably result in negative comments about the implementation
quality.


I don't know ... I'm kind of keen on compilers flagging as much
non-sanctioned behaviour as they can, and reserved identifiers seem to
be an easier thing to catch than [the general case of] i = i++.
(Quietly breaking when such an identifier is used is, however,
sub-optimal.)

mlp
Nov 14 '05 #5
CBFalconer wrote:
Walter Roberson wrote:
John Smith <JS****@mail.net> wrote:

I understand that C identifiers beginning with str are reserved for
future implementations. Do variable and function names beginning
with str in my existing code, which is for my own use only,
constitute a functional bug or a potential for undefined behaviour?
If new str* are added to the standard (possibly as an addendum
rather than a formal revision), and they happen to overlap your
names, then there is the potential that if you recompiled your code
with a compiler that had the new functions, that you could run into
symbol overlaps; that could result in anything from a compile error
for mismatched prototypes, to a refusal to link, to the code not
doing what you wanted because the wrong function was called.

The idea is future-proofing: if you avoid str* now then you
don't have to change your code later.

It's more than that. Those names are reserved for the
implementation. So an implementor can provide a functions
strblah(...) which does whatever he wishes, place it in the
library, and call it from his internal operations. If you replace
it you can cause well known standard library functions to fail.


This is the kind of thing I was concerned about. I suppose one can
examine the implementation's headers to find out if this is the case.
You gotta know the territory.

I will concede in advance that such an event is unlikely, and would
probably result in negative comments about the implementation
quality.

Nov 14 '05 #6
CBFalconer wrote:

It's more than that. Those names are reserved for the
implementation. So an implementor can provide a functions
strblah(...) which does whatever he wishes, place it in the
library, and call it from his internal operations. If you replace
it you can cause well known standard library functions to fail.
You gotta know the territory.

I will concede in advance that such an event is unlikely, and would
probably result in negative comments about the implementation
quality.


Not necessarily. SuS includes strdup, so an application-defined
function of that name could very easily cause a conflict, without
inviting negative comments.

--
================================================== ======================
Ian Pilcher i.*******@comcast.net
================================================== ======================
Nov 14 '05 #7
Ian Pilcher wrote:
CBFalconer wrote:

It's more than that. Those names are reserved for the
implementation. So an implementor can provide a functions
strblah(...) which does whatever he wishes, place it in the
library, and call it from his internal operations. If you replace
it you can cause well known standard library functions to fail.
You gotta know the territory.

I will concede in advance that such an event is unlikely, and would
probably result in negative comments about the implementation
quality.


Not necessarily. SuS includes strdup, so an application-defined
function of that name could very easily cause a conflict, without
inviting negative comments.


The smarter implementor will create __strdup, and put a #define in
the appropriate header file (possibly with guards for pedantic
conformity etc.) such as:

#define strdup __strdup

and the problem goes away when the appropriate header is not
included.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #8
CBFalconer wrote:

The smarter implementor will create __strdup, and put a #define in
the appropriate header file (possibly with guards for pedantic
conformity etc.) such as:

#define strdup __strdup

and the problem goes away when the appropriate header is not
included.


Good point, however ...

strdup is declared in <string.h>. Any translation unit that makes use
of an application-defined strdup it likely to also make use of other
functions declared in this header.

Either way, the reasons for not using str... names are good.

--
================================================== ======================
Ian Pilcher i.*******@comcast.net
================================================== ======================
Nov 14 '05 #9
in comp.lang.c i read:
I suppose one can examine the implementation's headers to find out if this
is the case.


every one of them you use? will you even remember to check each new
implementation as you begin using it? will you check every implementation
each time it is updated? yes, that's the scope of the issue -- save
yourself the hassle, stay away from str*, and is*, mem*, to* and wcs*. is*
surprises lots of people (e.g., int isactive();). but there is hope, the
reservation is only when the identifier has external linkage and the prefix
is followed by a lowercase letter, so an underscore gets you back into the
safe zone without much disruption. in theory an uppercase letter will too,
but external identifiers aren't required to be case sensitive so it might
also bite you -- stick with the underscore.

also an initial E if followed by an uppercase letter or a decimal digit.

also an initial LC, SIG or SIG_ if followed by an uppercase letter.

and also, of course, those with an initial underscore.

see <http://oakroadsystems.com/tech/c-predef.htm> for a more involved
discussion of the issues.

--
a signature
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
6650
by: Derek | last post by:
The company where I work uses a naming convention that I have never used before. They use mixed-case letters for public member functions, but lower-case with underscores for the rest, like this:...
2
3758
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
48
1756
by: Robert Jacobson | last post by:
Hello all, If I have a class called "Foo," is there a preferred naming convention for iterating through each Foo instance in a collection of Foos? I've seen several different variations, even...
0
1721
by: Carl Colijn | last post by:
Hi all, Disclaimer: before I might trigger your "let's start a holy war!" button, I'd like to say I'm not intended to; I just post this message to get some input and not to promote "Yet Another...
2
1796
by: John Salerno | last post by:
After reading the PEP, I'm still not quite sure if there is a recommended (or widely preferred) method of naming variables. Here are the relevant bits: > Global Variable Names > > (Let's...
8
2072
by: Daz | last post by:
Hi all! This question may hopefully spark a little debate, but my problem is this: I am sure it's not just me who struggles to think up names for variables. Obviously, thinking up a name...
14
1578
by: rsine | last post by:
I did a recent post about what the standard was for naming a string builder object. My concern was that I did not what to use "str" prefix since this is used for strings but did not know what to...
4
1759
by: robear | last post by:
A while ago, I found a web page that describe an array of naming conventions when diming a variabe. For instance: tbl for table, str for string, i for integer.. (eg: tblMyTable, strMyString,...
1
2131
by: mk | last post by:
http://www.python.org/dev/peps/pep-0008/ "Function Names Function names should be lowercase, with words separated by underscores as necessary to improve readability." However, this PEP does...
0
7064
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7315
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5559
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4991
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4665
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3147
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.