memory problem..

G

Gianni Mariani

aki said:
//defined in header file
struct authProt
{
uint8_t type;
uint8_t length;
uint16_t authprot;

};

//in main file

authProt ap;

----
----
memberfun();

// In memberfunc()

ap.type=1; // there is segmentaion fault here i do not know why?


any comments please?

It appears the C++ code is correct - this would be a platform specific
issue. At a guess, it could be a name collission (is there anything
else named ap?). Try changing it's name (ap).
 
A

aki

//defined in header file
struct authProt
{
uint8_t type;
uint8_t length;
uint16_t authprot;

};

//in main file

authProt ap;

----
----
memberfun();

// In memberfunc()

ap.type=1; // there is segmentaion fault here i do not know why?


any comments please?
thanks
aki
 
S

sam_cit

//defined in header file
struct authProt
{
uint8_t type;
uint8_t length;
uint16_t authprot;

};

//in main file

authProt ap;

----
----
memberfun();

// In memberfunc()

ap.type=1; // there is segmentaion fault here i do not know why?

any comments please?
thanks
aki

you have just declared the object, have you allocated space for the
same with new operator?
 
I

Ian Collins

aki said:
//defined in header file
struct authProt
{
uint8_t type;
uint8_t length;
uint16_t authprot;

};

//in main file

authProt ap;

----
----
memberfun();

// In memberfunc()

ap.type=1; // there is segmentaion fault here i do not know why?


any comments please?

Post something that compiles and shows your problem.
 
S

Stefan Naewe

you have just declared the object, have you allocated space for the
same with new operator?

Why should he?

If I say


ClassName foo;


then there's no need to 'new' anything.


Stefan
 
A

aki

you have just declared the object, have you allocated space for the
same with new operator?

do i need separate memory allocation..
if i am right ... memory for object is created when its declared...
 
J

James Kanze

On May 4, 11:38 am, (e-mail address removed) wrote:
do i need separate memory allocation..
if i am right ... memory for object is created when its declared...

When it is defined, not just declared.

Regretfully, you don't provide enough context for me to really
say anything. If "authProt ap;" is in global scope, it is a
definition, and there shouldn't be any problem. You speak of
"memberfunc()", however: member of what? And where is ap
defined, and how is memberfunc called?
 
J

Jim Langston

aki said:
//defined in header file
struct authProt
{
uint8_t type;
uint8_t length;
uint16_t authprot;

};

//in main file

authProt ap;

----
----
memberfun();

// In memberfunc()

ap.type=1; // there is segmentaion fault here i do not know why?


any comments please?

Nothing per se wrong with that code, it should run fine. Which means your
problem is elsewhere and that's just where it's cropping up. It could be
buffer overflow somewhere or something else. The only way we could know is
if you could give us a small compilable program that gives a segmentation
fault with this problem.
 
K

kingfox

//defined in header file
struct authProt
{
uint8_t type;
uint8_t length;
uint16_t authprot;

};

//in main file

authProt ap;

----
----
memberfun();

// In memberfunc()

ap.type=1; // there is segmentaion fault here i do not know why?

any comments please?
thanks
aki

The code you posted should work OK. I think there must be other code
that damage the memory space of "ap". We need a small code which will
cause the fault so that we can give you more help.
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top