Caps convention.

M

Malcolm

Use all lower case for ansi c functions, and Capitalise For
Platform-Specific.

If you call something with caps, then your function name requires caps
itself.
 
T

Thomas Matthews

Malcolm said:
Use all lower case for ansi c functions, and Capitalise For
Platform-Specific.

If you call something with caps, then your function name requires caps
itself.

The common style is to use all-caps for constants and macros.
Function name styles differ:
leading word starts lowercase followed by Capitalized words:
thisIsMyFunction
same thing, using underscores:
this_Was_My_Function
starting with Captials:
ThisIsAnotherFunction
This_May_Be_More_Readable
as you suggested:
anansicfunction
another_ansi_function

However, most all good coding styles don't permit function names
to start with '_' (underscores) as these are reserved for
implementations.

This is a religous issue: all a matter of faith. As long as you
are consistent and the names are readble, any style will do. Just
as there is no best religion, there is no best coding style.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
 
E

E. Robert Tisdale

No!
That would imply that your API *depends* upon
details of its implementation.
The common style is to use all-caps for constants and macros.

This is an anachronism.
Function name styles differ:
leading word starts lowercase followed by Capitalized words:
thisIsMyFunction
same thing, using underscores:
this_Was_My_Function
starting with Captials:
ThisIsAnotherFunction
This_May_Be_More_Readable
as you suggested:
anansicfunction
another_ansi_function

These aren't really styles. The are typing shortcuts
for programmers with a missing shift key.
The idea was that because capital letters and underscore
required the programmer to hold down the shift key,
they slowed down typing (meaning productivity).
The first style above is a compromise
between readability and typing efficiency.
However, most all good coding styles
don't permit function names to start with '_' (underscores)
as these are reserved for implementations.

Again, this rule has nothing to do with style.
It's just a way to avoid conflicts with the implementation.
This is a religious issue: all a matter of faith.
As long as you are consistent and the names are readable,
any style will do.
Just as there is no best religion, there is no best coding style.

Yes, but no "true believer" will agree with you.
 
R

Richard Heathfield

Malcolm said:
Use all lower case for ansi c functions, and Capitalise For
Platform-Specific.

If you call something with caps, then your function name requires caps
itself.

Taken to its logical conclusion, this requires you to define your entry
point as Main() - and then it won't link.

Duh.
 
A

Arthur J. O'Dwyer

Use all lower case for [ANSI C] functions, and Capitalise For
Platform-Specific.

If you call something with caps, then your function name requires caps
itself.

Taken to its logical conclusion, this requires you to define your entry
point as Main() - and then it won't link.

Only if your main function is Platform-Specific. And in that case
it's off-topic for comp.lang.c anyway, and if you do post it,
*no matter* the capitalization, all you'll get are smiley posts
claiming that it won't link on [your OS here]. No harm, no foul.
(-:

FWIW, except for Malcolm's miscapitalization of the terms "ANSI C",
I basically agree with his statement. I just don't think it really
needed to be broadcast to the world, any more than it would be
appropriate to start a new thread in alt.usage.english to say,
"Start a new paragraph when there's a new speaker," or in comp.programming
to point out that the worst-case running time of Quicksort is O(n^2).
Those who care, already know.

-Arthur
 
A

Alexander Bartolich

begin E. Robert Tisdale:
These aren't really styles. The are typing shortcuts
for programmers with a missing shift key.
The idea was that because capital letters and underscore
required the programmer to hold down the shift key,
they slowed down typing (meaning productivity).

And how do you get an underscore without pressing shift?
 
M

Malcolm

Richard Heathfield said:
Taken to its logical conclusion, this requires you to define your entry
point as Main() - and then it won't link.

Duh.
So this is an issue for comp.std.c. If programs beginning main() were
constrained to be portable ANSI C, whilst platform-specific can start
Main(), then this is a powerful incentive for people to write portable
programs.

Actually main() is often not the entry point for non-ANSI programs.
 
R

Richard Heathfield

Arthur said:
Malcolm said:
Use all lower case for [ANSI C] functions, and Capitalise For
Platform-Specific.

If you call something with caps, then your function name requires caps
itself.

Taken to its logical conclusion, this requires you to define your entry
point as Main() - and then it won't link.

Only if your main function is Platform-Specific.

Or if it /calls/ something Platform-Specific, according to Malcolm.

FWIW, except for Malcolm's miscapitalization of the terms "ANSI C",
I basically agree with his statement. I just don't think it really
needed to be broadcast to the world, any more than it would be
appropriate to start a new thread in alt.usage.english to say,
"Start a new paragraph when there's a new speaker," or in comp.programming
to point out that the worst-case running time of Quicksort is O(n^2).
Those who care, already know.

Quite so. But since we're being so public about it at present, my own
preference is xyz_CamelCase for function names and parameter names in the
xyz library (or, perhaps, the library for which xyz is a suitable
contraction or abbreviation), SEPARATED_UPPER_CASE for type names and
macros, and whatever I feel like for local identifiers.
 
M

Mark McIntyre

begin E. Robert Tisdale:

And how do you get an underscore without pressing shift?

By using the right keyboard. Not all keyboards have the same layout as
your current (possibly Austrian) one. Some keyboards used to lack the
angles <>, others lacked square brackets, at signs etc. Some Mac ones
still do lack a hash #.
All the world's not a VT102 you know...
 
M

Mark McIntyre

begin Mark McIntyre:

Nope. I do enjoy fast access to square, curly and angle brackets.

If you reread my post, you'll notice that I didn't say whether you
did, or did not have that. Nor, frankly do I care.
 
T

Thomas Stegen

Richard said:
Quite so. But since we're being so public about it at present, my own
preference is xyz_CamelCase for function names and parameter names in the
xyz library (or, perhaps, the library for which xyz is a suitable
contraction or abbreviation), SEPARATED_UPPER_CASE for type names and
macros, and whatever I feel like for local identifiers.

Which reminds me. I wouls like to see namespaces in C. Just a very
simple thing, nothing very fancy.

Putting something in a namespace.
Accessing the namespace explicitly.
Maybe a way of setting the namespace currently being used.

As simple as that.

What do people think?
 
A

Alexander Bartolich

begin Thomas Stegen:
Which reminds me. I wouls like to see namespaces in C.
Just a very simple thing, nothing very fancy.

No, it ain't not simple.

Eventually all symbols end up in one global scope, the symbol table
of the linker. C++ uses a technique called mangled names to work
around this. Think of it as an automatic translation of std::string
to _std_string or something similar, only that C++ also adds argument
types to that.

The net effect are almost unreadable map files, linking problems
between object code from different compilers, additional syntax to
switch back to old behaviour (extern "C"), and increased resource
demands for the linker.

You can use C++ as A Better C (TM), if you like.
The ecological niche of C is bare bones programming, though.
 
A

Alexander Bartolich

begin Mark McIntyre:
If you reread my post, you'll notice that I didn't say whether you
did, or did not have that. Nor, frankly do I care.

Thomas Matthews wrote:
# These aren't really styles. The are typing shortcuts
# for programmers with a missing shift key.
# The idea was that because capital letters and underscore
# required the programmer to hold down the shift key,
# they slowed down typing (meaning productivity).

I think that's an urban legend.
 
C

CBFalconer

Mark said:
.... snip ...

If you reread my post, you'll notice that I didn't say whether you
did, or did not have that. Nor, frankly do I care.

You cruel unfeeling beast.
 
J

Joe Wright

Richard said:
Malcolm wrote:

Use all lower case for [ANSI C] functions, and Capitalise For
Platform-Specific.

If you call something with caps, then your function name requires caps
itself.

Taken to its logical conclusion, this requires you to define your entry
point as Main() - and then it won't link.

Only if your main function is Platform-Specific.

Or if it /calls/ something Platform-Specific, according to Malcolm.

FWIW, except for Malcolm's miscapitalization of the terms "ANSI C",
I basically agree with his statement. I just don't think it really
needed to be broadcast to the world, any more than it would be
appropriate to start a new thread in alt.usage.english to say,
"Start a new paragraph when there's a new speaker," or in comp.programming
to point out that the worst-case running time of Quicksort is O(n^2).
Those who care, already know.

Quite so. But since we're being so public about it at present, my own
preference is xyz_CamelCase for function names and parameter names in the
xyz library (or, perhaps, the library for which xyz is a suitable
contraction or abbreviation), SEPARATED_UPPER_CASE for type names and
macros, and whatever I feel like for local identifiers.
If I declare a function..
void * Malloc(size_t);
...the compiler is not confused at all. It knows that Malloc is not
malloc. But what about the linker? Are the symbols and symbol tables
used in linking alse case sensitive? Can I declare Malloc in one
translation unit and define it in another and be ensured that they will
link?
 
R

Richard Heathfield

Joe said:
If I declare a function..
void * Malloc(size_t);
..the compiler is not confused at all. It knows that Malloc is not
malloc. But what about the linker? Are the symbols and symbol tables
used in linking alse case sensitive? Can I declare Malloc in one
translation unit and define it in another and be ensured that they will
link?

In C90, you can't be sure.

"The implementation may further restrict the significance of an external
name (an identifier that has external linkage) to six characters and may
ignore distinctions of alphabetical case for such names."

ISTR that this restriction has been removed (or at least, /effectively/
removed) in C99.
 
N

Nudge

Alexander said:
Thomas Matthews wrote:
# These aren't really styles. The are typing shortcuts
# for programmers with a missing shift key.
# The idea was that because capital letters and underscore
# required the programmer to hold down the shift key,
# they slowed down typing (meaning productivity).

It was Tisdale who said that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top