473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Init before anything else

Hello,

Consider this case:

Init(params) does some initialization and there is a function
Connect(params). The system starts and is idle until some one calls
Connect, as soon as first Connection is received and only on first
connection request Init() has to be called before serving Connection
request.
if(bInitialized) checks needs to be avoided as Connect() is invoked
several times. Init & Connect prototypes are different.

I have a solution, changing function pointers, any others??? Please
suggest...

thanks
-Paul.
Nov 14 '05 #1
6 1509
On 19 Aug 2004 19:50:52 -0700, bg*****@yahoo.com (Paul) wrote in
comp.lang.c:
Hello,

Consider this case:

Init(params) does some initialization and there is a function
Connect(params). The system starts and is idle until some one calls
Connect, as soon as first Connection is received and only on first
connection request Init() has to be called before serving Connection
request.
if(bInitialized) checks needs to be avoided as Connect() is invoked
several times. Init & Connect prototypes are different.
Why does the fact that Connect() is invoked several times mean that
"if(bInitialized) checks needs(sic) to be avoided"? It's the best way
to handle the situation.

return_type Connect(arguments)
{
static int bInitialized;

if (!bInitialized)
{
Init();
}

/* the rest of Connect() */
}
I have a solution, changing function pointers, any others??? Please
suggest...

thanks


What makes you think that function pointers are a better solution than
that? What reason do you have for not using a solution like the
above?

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
Mac
On Thu, 19 Aug 2004 22:16:35 -0500, Jack Klein wrote:
On 19 Aug 2004 19:50:52 -0700, bg*****@yahoo.com (Paul) wrote in
comp.lang.c:
Hello,

Consider this case:

Init(params) does some initialization and there is a function
Connect(params). The system starts and is idle until some one calls
Connect, as soon as first Connection is received and only on first
connection request Init() has to be called before serving Connection
request.
if(bInitialized) checks needs to be avoided as Connect() is invoked
several times. Init & Connect prototypes are different.
Why does the fact that Connect() is invoked several times mean that
"if(bInitialized) checks needs(sic) to be avoided"? It's the best way
to handle the situation.

return_type Connect(arguments)
{
static int bInitialized;

if (!bInitialized)
{
Init();

bInitialized = 1; }

/* the rest of Connect() */
}

[snip]

Or you could let Init set bInitilized to 1. Personally I would prefer to
see bInitialized altered immediately after it is tested, as I've
shown above.

--Mac

Nov 14 '05 #3
Mac <fo*@bar.net> wrote in message news:<pa****************************@bar.net>...
On Thu, 19 Aug 2004 22:16:35 -0500, Jack Klein wrote:
On 19 Aug 2004 19:50:52 -0700, bg*****@yahoo.com (Paul) wrote in
comp.lang.c:
Hello,

Consider this case:

Init(params) does some initialization and there is a function
Connect(params). The system starts and is idle until some one calls
Connect, as soon as first Connection is received and only on first
connection request Init() has to be called before serving Connection
request.
if(bInitialized) checks needs to be avoided as Connect() is invoked
several times. Init & Connect prototypes are different.


Why does the fact that Connect() is invoked several times mean that
"if(bInitialized) checks needs(sic) to be avoided"? It's the best way
to handle the situation.

return_type Connect(arguments)
{
static int bInitialized;

if (!bInitialized)
{
Init();

bInitialized = 1;
}

/* the rest of Connect() */
}

[snip]

Or you could let Init set bInitilized to 1. Personally I would prefer to
see bInitialized altered immediately after it is tested, as I've
shown above.

--Mac


I feel if(!bInitialized) check is redundant, as bInitialize = 1 for
ever after initialization. Function pointer solution is mentioned just
to avoid discussion on it, I don't say its a good solution considering
function call overhead.

I came across this code, which is in C++ (c communicty please excuse)
but its here to demonstrate the concept, I wonder if we can do
something like this in C.

return_type Init(args)
{
//some code
}
class A
{
A()//C'tor
{
Init(args);
}
};
return_type Connect(args)
{
static A a;
//some code
}

Hey C guys, please don't fire me for posting this C++ code here,
concept is great isn't it.

Cheers,
-Paul
Nov 14 '05 #4
Paul wrote:
Mac <fo*@bar.net> wrote in message news:<pa****************************@bar.net>...
On Thu, 19 Aug 2004 22:16:35 -0500, Jack Klein wrote:

On 19 Aug 2004 19:50:52 -0700, bg*****@yahoo.com (Paul) wrote in
comp.lang.c:
Hello,

Consider this case:

Init(params) does some initialization and there is a function
Connect(params). The system starts and is idle until some one calls
Connect, as soon as first Connection is received and only on first
connection request Init() has to be called before serving Connection
request.
if(bInitialized) checks needs to be avoided as Connect() is invoked
several times. Init & Connect prototypes are different.

Why does the fact that Connect() is invoked several times mean that
"if(bInitialized) checks needs(sic) to be avoided"? It's the best way
to handle the situation.

return_type Connect(arguments)
{
static int bInitialized;

if (!bInitialized)
{
Init();


bInitialized = 1;
}

/* the rest of Connect() */
}


[snip]

Or you could let Init set bInitilized to 1. Personally I would prefer to
see bInitialized altered immediately after it is tested, as I've
shown above.

--Mac

I feel if(!bInitialized) check is redundant, as bInitialize = 1 for
ever after initialization. Function pointer solution is mentioned just
to avoid discussion on it, I don't say its a good solution considering
function call overhead.

I came across this code, which is in C++ (c communicty please excuse)
but its here to demonstrate the concept, I wonder if we can do
something like this in C.

return_type Init(args)
{
//some code
}
class A
{
A()//C'tor
{
Init(args);
}
};
return_type Connect(args)
{
static A a;
//some code
}

Hey C guys, please don't fire me for posting this C++ code here,
concept is great isn't it.


Then try something like this:

return_type Connect(arguments)
{
static int bInitialized = Init(); /*assuming Init() returns int*/

/* the rest of Connect() */
}

Mark

--
<<Remove the del for email>>
Nov 14 '05 #5
Capstar <ne**@deleg.homeip.net> wrote in message news:<cg**********@news.tudelft.nl>...
Paul wrote:
Mac <fo*@bar.net> wrote in message news:<pa****************************@bar.net>...
On Thu, 19 Aug 2004 22:16:35 -0500, Jack Klein wrote:
On 19 Aug 2004 19:50:52 -0700, bg*****@yahoo.com (Paul) wrote in
comp.lang.c:
>Hello,
>
>Consider this case:
>
>Init(params) does some initialization and there is a function
>Connect(params). The system starts and is idle until some one calls
>Connect, as soon as first Connection is received and only on first
>connection request Init() has to be called before serving Connection
>request.
>if(bInitialized) checks needs to be avoided as Connect() is invoked
>several times. Init & Connect prototypes are different.

Why does the fact that Connect() is invoked several times mean that
"if(bInitialized) checks needs(sic) to be avoided"? It's the best way
to handle the situation.

return_type Connect(arguments)
{
static int bInitialized;

if (!bInitialized)
{
Init();

bInitialized = 1;

}

/* the rest of Connect() */
}
[snip]

Or you could let Init set bInitilized to 1. Personally I would prefer to
see bInitialized altered immediately after it is tested, as I've
shown above.

--Mac

I feel if(!bInitialized) check is redundant, as bInitialize = 1 for
ever after initialization. Function pointer solution is mentioned just
to avoid discussion on it, I don't say its a good solution considering
function call overhead.

I came across this code, which is in C++ (c communicty please excuse)
but its here to demonstrate the concept, I wonder if we can do
something like this in C.

return_type Init(args)
{
//some code
}
class A
{
A()//C'tor
{
Init(args);
}
};
return_type Connect(args)
{
static A a;
//some code
}

Hey C guys, please don't fire me for posting this C++ code here,
concept is great isn't it.


Then try something like this:

return_type Connect(arguments)
{
static int bInitialized = Init(); /*assuming Init() returns int*/

/* the rest of Connect() */
}

Mark


this doesn't work, since initilizers needs to be constants in C.
Or do we accept C++ wins over C here, then why the hell we are still
programming in C?
Nov 14 '05 #6
Paul wrote:
Capstar <ne**@deleg.homeip.net> wrote in message news:<cg**********@news.tudelft.nl>...
Paul wrote:
Mac <fo*@bar.net> wrote in message news:<pa****************************@bar.net>...
On Thu, 19 Aug 2004 22:16:35 -0500, Jack Klein wrote:

>On 19 Aug 2004 19:50:52 -0700, bg*****@yahoo.com (Paul) wrote in
>comp.lang.c:
>
>
>
>>Hello,
>>
>>Consider this case:
>>
>>Init(params) does some initialization and there is a function
>>Connect(params). The system starts and is idle until some one calls
>>Connect, as soon as first Connection is received and only on first
>>connection request Init() has to be called before serving Connection
>>request.
>>if(bInitialized) checks needs to be avoided as Connect() is invoked
>>several times. Init & Connect prototypes are different.
>
>Why does the fact that Connect() is invoked several times mean that
>"if(bInitialized) checks needs(sic) to be avoided"? It's the best way
>to handle the situation.
>
>return_type Connect(arguments)
>{
> static int bInitialized;
>
> if (!bInitialized)
> {
> Init();

bInitialized = 1;
> }
>
> /* the rest of Connect() */
>}
>

[snip]

Or you could let Init set bInitilized to 1. Personally I would prefer to
see bInitialized altered immediately after it is tested, as I've
shown above.

--Mac
I feel if(!bInitialized) check is redundant, as bInitialize = 1 for
ever after initialization. Function pointer solution is mentioned just
to avoid discussion on it, I don't say its a good solution considering
function call overhead.

I came across this code, which is in C++ (c communicty please excuse)
but its here to demonstrate the concept, I wonder if we can do
something like this in C.

return_type Init(args)
{
//some code
}
class A
{
A()//C'tor
{
Init(args);
}
};
return_type Connect(args)
{
static A a;
//some code
}

Hey C guys, please don't fire me for posting this C++ code here,
concept is great isn't it.


Then try something like this:

return_type Connect(arguments)
{
static int bInitialized = Init(); /*assuming Init() returns int*/

/* the rest of Connect() */
}

Mark

this doesn't work, since initilizers needs to be constants in C.
Or do we accept C++ wins over C here, then why the hell we are still
programming in C?


Hmmm, good point. I know I should have tried it before posting. :)
--
<<Remove the del for email>>
Nov 14 '05 #7

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

Similar topics

4
by: Anatoly | last post by:
Put any control on web page. create Init event for ths control. Write Response.Write("here") inside this event. Compile\build\run. I never saw "here" string appear on web page. Why???
1
by: mato | last post by:
this is what i experienced in my web application and i realy do not understand. this is my web page class behind public class MyWebPage : System.Web.UI.Page { //some page controls ..... ...
10
by: Wylbur via DotNetMonster.com | last post by:
Hello to all of you geniuses, I'm having a problem trying to get an Init handler to fire for a Placeholder control at the initialization phase. I’ve posted this problem to 3 other ASP.NET...
6
by: Shimon Sim | last post by:
I have Panel control on the page. I am handling Init event for it. It doesn't seem to fire at all. Why? Thank you Shimon.
18
by: Ronald Bruck | last post by:
I have several routines which are used millions of times in my programs, using the Gnu multi-precision software's floating-point reals (see <http://www.swox.se/gmp>). These are of type mpf_t, and...
0
by: Kevin Jackson | last post by:
Is there any way to get a shot to hook into server controls on the page Init event. The following code doesn't work because it the page controls must of already had their Init event called. ...
4
by: Jess | last post by:
Hello, I tried several books to find out the details of object initialization. Unfortunately, I'm still confused by two specific concepts, namely default-initialization and...
3
by: Maxim Veksler | last post by:
Hi list, I'm working on writing sanity check script, and for aesthetic reasons I would like the output be in the formatted like the gentoo init script output, that is: """ Check for something...
2
by: Christof Warlich | last post by:
Hi, I'm working on a (template) library that is up to now entirely implemented in header-files. This makes the library quite convenient to use as no extra object code needs to be linked when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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
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,...

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.