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 9 1346
In article <kIU6e.983315$8 l.628412@pd7tw1 no>,
John Smith <JS****@mail.ne t> 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
Walter Roberson wrote: In article <kIU6e.983315$8 l.628412@pd7tw1 no>, John Smith <JS****@mail.ne t> 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
Walter Roberson wrote: John Smith <JS****@mail.ne t> 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.c om, 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
CBFalconer <cb********@yah oo.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
CBFalconer wrote: Walter Roberson wrote:
John Smith <JS****@mail.ne t> 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.
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.*******@comca st.net
=============== =============== =============== =============== ============
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.c om, 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
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.*******@comca st.net
=============== =============== =============== =============== ============
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
class Foo
{
public:
void somePublicMemberFunction();
protected:
|
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
produce two messages having the same message digest.
That conjecture is false, as demonstrated by Wang, Feng, Lai and
Yu in 2004 . Just recently, Wang, Yu, and Lin showed a short-
cut solution for finding collisions in SHA-1 . Their result
|
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 in the MSDN documentation:
#1:
For each Foo as Foo in Foos
...
|
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 Naming Convention". It's a bit of a
long post, but I've spent the past few days on perfecting this, finally came
to the conclusion that maybe I went a bit overboard with it, almost willing
to just say "the @#$ with it" but I didn't want to let it...
|
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 hope that these variables are meant for use inside one module
> only.) The conventions are about the same as those for functions.
>
> Modules that are designed for use via "from M import *" should use the
| |
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 'can' be simple, but when you
are trying to create variable names that are easy to remember,
descriptive, and not more than say 15-20 characters long, I come a
cropper! Would anyone be able to give me any pointers as to how I can
|
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 use in its
place. A few responses I received indicated such prefixing is no
longer necessary in .Net and should be abandoned. Is this the correct
approach? I am striving hard to make sure I use best practices in my
code.
-Thanks
|
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, iMyint, etc)
I know there isn't a hard or fast rule of how your variable names
should be formed, but my real question is does anyone have any links to
web pages (M or other) that suggest types of naming conventions
|
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 not recommend any particular style for naming
regular (local) variables.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |