question on globals

S

srblinux

Hi all,
If a program-1 is written with Globals without initilisation and
program-2 was written with Globals with initilisation, But
program-2 is working fine but program-1 is giving problem
why is it so?
Thanks in advance,
with regards,
Bab
 
P

Pietro Cerutti

Hi all,
If a program-1 is written with Globals without initilisation and
program-2 was written with Globals with initilisation, But
program-2 is working fine but program-1 is giving problem
why is it so?
Thanks in advance,
with regards,
Bab

Yes.
 
R

Richard Heathfield

(e-mail address removed) said:
Hi all,
If a program-1 is written with Globals without initilisation and
program-2 was written with Globals with initilisation, But
program-2 is working fine but program-1 is giving problem
why is it so?

File scope objects are default-initialised to 0, NULL, or 0.0 (recursively
for aggregates such as structures, unions, and arrays). It is likely that
the default initialisation is inadequate for your purposes.

Without seeing your code, I can't really help you further.
 
J

James Kuyper

Hi all,
If a program-1 is written with Globals without initilisation and
program-2 was written with Globals with initilisation, But
program-2 is working fine but program-1 is giving problem
why is it so?

Most likely, the programs were written in such a way that it matters
what values the globals were initialized with; this is pretty
commonplace. With no explicit initialization, they are implicitly
zero-initialized. If program 2 initialized the variables with non-zero
values, that explains why the two programs have different behavior.
 
B

Ben Pfaff

If a program-1 is written with Globals without initilisation and
program-2 was written with Globals with initilisation, But
program-2 is working fine but program-1 is giving problem
why is it so?

Program 1 has a bug. If you show us the code, we can probably
point it out.
 
R

Richard Bos

Ben Pfaff said:
Program 1 has a bug. If you show us the code, we can probably
point it out.

I would say it's quite likely, too, that both program 1 and program 2
have a bug, probably the same one, but the non-zero initialisations in
program 2 hide it, whereas the zero initialisations in program 1 do not.

Richard
 
D

dj3vande

I would say it's quite likely, too, that both program 1 and program 2
have a bug, probably the same one, but the non-zero initialisations in
program 2 hide it, whereas the zero initialisations in program 1 do not.

I suspect it's slightly more likely that the lack of nonzero
initializations IS the bug.


dave

--
Dave Vandervies dj3vande at eskimo dot com
Didn't I read here several weeks ago [...]
I couldn't say, not having DMA to your brain, but I do recall it being posted
here. --David P. Murphy and Dave Buckles in the scary devil monastery
 

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
474,260
Messages
2,571,308
Members
47,959
Latest member
MauricioHo

Latest Threads

Top