I recently inherited some older C code and saw something I haven't really
seen before. I noticed it as it fails to compile at my home computer, as it
has a newer (4.x vs 3.x ) gcc compiler.
Its a private function, inside a function. Something like this.
void myFunc(...) {
static void myPrivateFunc(. ..) {
}
...
return;
}
I assume its failing to compile, because the private function is declared
static. I guess what I'm comfused at is I havent' really seen functions
declared in functions before. Could this have been done for performance
reasons or something? The original author has about 5 different C files,
each with one of these private functions, they all do about the same thing.
There basically some masking and quit math on the function parameters.
I'm just wondering if its performance as this is some intensive data
decoding code. Mucking with lots of data at the bit per bit level. 9 1984
Grant Schoep wrote: void myFunc(...) { static void myPrivateFunc(. ..) { } ... return; }
I assume its failing to compile, because the private function is declared static.
No, it fails because nested functions are not allowed in standard C.
Grant Schoep wrote: I recently inherited some older C code and saw something I haven't really seen before. I noticed it as it fails to compile at my home computer, as it has a newer (4.x vs 3.x ) gcc compiler.
Its a private function, inside a function. Something like this.
void myFunc(...) { static void myPrivateFunc(. ..) { } ... return; }
I assume its failing to compile, because the private function is declared static. I guess what I'm comfused at is I havent' really seen functions declared in functions before. Could this have been done for performance reasons or something? The original author has about 5 different C files, each with one of these private functions, they all do about the same thing. There basically some masking and quit math on the function parameters.
I'm just wondering if its performance as this is some intensive data decoding code. Mucking with lots of data at the bit per bit level.
Gnu C has an extension like this - so maybe it's some gcc code?
--
==============
Not a pedant
==============
"pemo" writes: Grant Schoep wrote: I recently inherited some older C code and saw something I haven't really seen before. I noticed it as it fails to compile at my home computer, as it has a newer (4.x vs 3.x ) gcc compiler.
Its a private function, inside a function. Something like this.
void myFunc(...) { static void myPrivateFunc(. ..) { } ... return; }
I assume its failing to compile, because the private function is declared static. I guess what I'm comfused at is I havent' really seen functions declared in functions before. Could this have been done for performance reasons or something? The original author has about 5 different C files, each with one of these private functions, they all do about the same thing. There basically some masking and quit math on the function parameters.
I'm just wondering if its performance as this is some intensive data decoding code. Mucking with lots of data at the bit per bit level.
Gnu C has an extension like this - so maybe it's some gcc code?
I think that's a good guess. You can put a function prototype within a C
function, but even that is rarely done. I guess it limits visibility. But
you can't put an actual function definition inside a function. It would be
nice if you could.
Grant Schoep wrote: I recently inherited some older C code and saw something I haven't really seen before. I noticed it as it fails to compile at my home computer, as it has a newer (4.x vs 3.x ) gcc compiler.
Its a private function, inside a function. Something like this.
void myFunc(...) { static void myPrivateFunc(. ..) { } ... return; }
I assume its failing to compile, because the private function is declared static. I guess what I'm comfused at is I havent' really seen functions declared in functions before. Could this have been done for performance reasons or something? The original author has about 5 different C files, each with one of these private functions, they all do about the same thing. There basically some masking and quit math on the function parameters.
does the author come from pascal development ? I'm just wondering if its performance as this is some intensive data decoding code. Mucking with lots of data at the bit per bit level.
.. Gnu C has an extension like this - so maybe it's some gcc code?
It is gnu, gnu 3.x seems to allow it. where as gnu 4.x does not. I seem to
remeber gnu 4.x talk that is getting much more adherent to standards.
I'm just going to pull the function out of the function. And keep it
"private" by not putting in the header. Since the same function, thought 5
different implementations , in 5 differetn files wil have the same name.
I'll just come up with a good uniq name for the 5 different functions. Its
actually fairly easy to test many aspects of this change, including
performance, as its a big data decom routine that we do analyize its
regular performance.
Grant Schoep wrote: I'm just going to pull the function out of the function. And keep it "private" by not putting in the header. Since the same function, thought 5 different implementations , in 5 differetn files wil have the same name. I'll just come up with a good uniq name for the 5 different functions.
Just declare them `static`. It'll make your function(s) "private", i.e.
make them have internal linkage. Then you can have as many as you like
with the same name (in different compilation units, obviously).
--
BR, Vladimir
Logic is a little bird, sitting in a tree; that smells *awful*.
"Vladimir S. Oka" <no****@btopenw orld.com> writes: Grant Schoep wrote: I'm just going to pull the function out of the function. And keep it "private" by not putting in the header. Since the same function, thought 5 different implementations , in 5 differetn files wil have the same name. I'll just come up with a good uniq name for the 5 different functions. Just declare them `static`. It'll make your function(s) "private", i.e. make them have internal linkage. Then you can have as many as you like with the same name (in different compilation units, obviously).
One thing that nested functions give you is the ability to refer to
declarations in the enclosing function. If your nested functions do
that, you'll need to find some other way to get to the information.
-- BR, Vladimir
Logic is a little bird, sitting in a tree; that smells *awful*.
"Logic is a little bird, tweeting in a meadow. Logic is a wreath of
pretty flowers which smell *bad*. Are your circuits registering
correctly? Your ears are green!" (If I recall correctly.)
--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Keith Thompson wrote: "Vladimir S. Oka" <no****@btopenw orld.com> writes: Grant Schoep wrote: I'm just going to pull the function out of the function. And keep it "private" by not putting in the header. Since the same function, thought 5 different implementations , in 5 differetn files wil have the same name. I'll just come up with a good uniq name for the 5 different functions.
Just declare them `static`. It'll make your function(s) "private", i.e. make them have internal linkage. Then you can have as many as you like with the same name (in different compilation units, obviously).
One thing that nested functions give you is the ability to refer to declarations in the enclosing function. If your nested functions do that, you'll need to find some other way to get to the information.
Good point. I must admit I sometimes miss Pascal-like ability to nest
functions. I don't think that adding this to C would break any existing
programs. or would it? Logic is a little bird, sitting in a tree; that smells *awful*.
"Logic is a little bird, tweeting in a meadow. Logic is a wreath of pretty flowers which smell *bad*. Are your circuits registering correctly? Your ears are green!" (If I recall correctly.)
Didn't know that. My sigs come from fortune (I'm cheap). ;-)
--
BR, Vladimir
Humpty Dumpty was pushed.
"Vladimir S. Oka" wrote: Grant Schoep wrote:
I'm just going to pull the function out of the function. And keep it "private" by not putting in the header. Since the same function, thought 5 different implementations , in 5 differetn files wil have the same name. I'll just come up with a good uniq name for the 5 different functions.
Just declare them `static`. It'll make your function(s) "private", i.e. make them have internal linkage. Then you can have as many as you like with the same name (in different compilation units, obviously).
AND keep it out of the header.
--
"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
More details at: <http://cfaj.freeshell. org/google/>
Also see <http://www.safalra.com/special/googlegroupsrep ly/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Rock |
last post by:
Hello,
in the last few days I've made my first few attempts at creating mixed C++
managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is
visible in those assemblies from a managed point-of-view I've noticed that:
1) for each managed and unmanaged C function (not C++ classes) I get a
public managed static method (defined on a 'Global Functions' class) in the
generated assembly with an export name of the form...
|
by: Andy |
last post by:
1) Is there any use of defining a class with a single constructor
declared in private scope? I am not asking a about private copy
constructors to always force pass/return by reference.
2) Is this in any way used to create singletons. Can someone say how?
Cheers,
Andy
|
by: Chris Mantoulidis |
last post by:
Forgive me if I'm wrong but I think there is something like an extra
member scope in classes.
for example:
class abc {
ostream & operator << (ostream &, const abc &);
istream & operator >> (istream &, abc &);
private:
|
by: Nemanja Trifunovic |
last post by:
Something I don't get it:
Say we have:
ref class Base {
virtual void SomeVirtualFunction()
{Console::WriteLine(L"Base");}
public:
void SomeAccessibleFunction()
{SomeVirtualFunction();}
|
by: Mike |
last post by:
Hi,
Just a simple question: why the compiler doesn't report error when
accessing a private member function inside a function having template
type ?
For example:
#include<iostream>
using namespace std;
| |
by: Victor |
last post by:
I just tried a test comparing a Function to a Private Function with this code:
<%
Option Explicit
dim X1
X1 = 9
Private Function RealTest(here)
RealTest = here + X1
End Function
|
by: v4vijayakumar |
last post by:
Why we need "virtual private member functions"? Why it is not an
(compile time) error?
|
by: zman77 |
last post by:
EDIT: -- forgot to mention... I am using Visual Studio 2005, on Win XP, on an intel machine
Hi.
This is my first post, though I've "lurked" for a while because I find these forums very helpful.
Ok my problem is the following. I have a class that contains a "MakeByteArray" function.
I have many objects of that class. Inside that function, I have a private variable,
that is NOT static. It seems that when I put all these objects in...
|
by: Peng Yu |
last post by:
Hi,
I'm wondering if there is something in namespace like the 'private'
keyword in class?
I want to define some class or function that can only be used within
that namespace.
Thanks,
Peng
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: 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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: 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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |