|
Luc Pattyn wrote: Is it still in active use?
Yes, especially in safety-critical applications - the company I work for uses it. It's also becoming more actively used in some security areas, especially when used in conjunction with SPARK[^].
Luc Pattyn wrote: is there an ADA#?
Yes[^], although it's not really active.
Luc Pattyn wrote: should we have a forum on it?
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Thanks.
It made me better understand your sig.
|
|
|
|
|
Along with a stirring of Cartman[^]...
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
You are so modest.
According to your explanation, parameters passed to function is essential value, whatever the type of object.As for point type, address of the point is actually passed.So as to these two points, we can say that p is a copy of str,which is their only relationship. This viewpoint seems to resolve my puzzle.
Another example,
void GetMemory(char* p)
{
if(p != NULL)
{
delete []p;
p = NULL;
}
if(p == NULL)
{
p = new char[1000];
*(p+10) = 'a';
}
}
int main()
{
char* str = NULL;
str = new char[100];
GetMemory(str);
}
Above code snippet indicates that before and after GetMemory(str); point str is being revised.I have no idea why such happens.
Much appreciate for your guys' kindness.
|
|
|
|
|
sharion wrote: Above code snippet indicates that before and after GetMemory(str);point str is being revised.I have no idea why such happens.
So if you used the code below, two different values are output? Not on any C++ compiler I tried it with
int main()
{
char* str = NULL;
str = new char[100];
std::cout << (int)str <<std::endl;
GetMemory(str);
std::cout << (int)str <<std::endl;
}
Of course, the memory that str points at is no longer allocated, so you don't want to be using str after the GetMemory call!
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
The value of point str is changed when second it is allocated memory. Do you agree?
Stuart Dootson wrote: Of course, the memory that str points at is no longer allocated, so you don't want to be using str after the GetMemory call!
Actually, str is allocated successfully after GetMemory .When you count the memory size of str between memory allocated two times you can draw this conclusion.
This snippet indicates a case of second memory allocated.In logical it may be weired.I post it only want to say GetMemory also change the point str when it passed by a point variable instead of point to a point(**) or reference to a point(*&).
Thanks a lot.
|
|
|
|
|
sharion wrote: The value of point str is changed when second it is allocated memory. Do you agree?
str is only assigned to once - the other time, it is p, which is a copy of str which is assigned.
sharion wrote: Actually, str is allocated successfully after GetMemory.When you count the memory size of str between memory allocated two times you can draw this conclusion.
Again, NO. str is assigned ONCE.
Let's go through the code, in the order that the code is executed:
int main()
{
char* str = NULL;
str = new char[100];
GetMemory(str);
void GetMemory(char* p)
{
if(p != NULL)
{
delete []p;
p = NULL;
}
if(p == NULL)
{
p = new char[1000];
*(p+10) = 'a';
}
}
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
First I must say when I wrote this snippet I agree with most of your point,that is p is only a copy of str, whatever you have done to p has nothing to do with str.
After I compile this snippet,I find something is wrong.
The first fact,you will find the value of *(str+10) is equal to 'a'.Now you should know str has been changed. This result comes from VS 2005 compiler.
Second fact,Furtherly,If you count the memory size by function strlen , you will find the memory size is also changed. Code snippet like this:
str = new char[100];
int n1= (int)strlen((const char*)str);
GetMemory(str);
int n2= (int)strlen((const char*)str);
When debug this snippet, you will get the result, that is n1 is equal to 112 and n2 is equal to 1016. The value of n1 and n2 seem strange but it is not we mainly talk about.The result should indicate memory is reallocated.
Here I list the result that the compiler output is only want to say whether I made some mistakes above or something else is not being considered when we talk this topic.
Thanks for your reply again and again with great patience.
P.S. Only a suggestion.I think our discussion takes up so much space in the website. Would you mind our discussion by email or other way? If it is inappropriate,forgot it
|
|
|
|
|
sharion wrote: The first fact,you will find the value of *(str+10) is equal to 'a'.
That is because you first deallocated the memory that str pointed at, then allocated a block that you assigned to p. When you deallocated the memory, you handed back the block that str pointed at to the C run-time. Then, when you allocated the new memory block, it just so happened that the first free address with enough storage was the one you just gave back to the run-time.
Now consider this code example - it's the same as yours with one line of code added. That line of code, however, is enough to stop the behaviour you've seen. If you run this, the memory that str points at will not be modified after calling GetMemory.
#include <iostream>
void GetMemory(char* p)
{
if(p != NULL)
{
delete []p;
p = NULL;
}
if(p == NULL)
{
p = new char[1000];
*(p+10) = 'a';
}
}
int main()
{
char* str = NULL;
str = new char[100];
char* str2 = new char[100];
GetMemory(str);
}
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Wo, that's fabulous.Thanks a lot.
|
|
|
|
|
I get compilation errors while using multiple header inclusion in Win32 console application. At the moment I use Visual Studio 2008.
EDCA.cpp:
#pragma once
#include "stdafx.h"
#include "mac.h"
#include "globals.h"
void main()
{
StaT as;
Mac asdf;
asdf.accesspoint = 0;
}
mac.h:
#pragma once
#ifndef mac_h
#define mac_h
#include "globals.h"
#define AC 4
enum StaT{
AP,
STA,
REP
};
class Mac{
public:
StaT type;
Mac () {}
};
#endif
globals.h:
#pragma once
#ifndef globals_h
#define globals_h
#include "mac.h"
extern const double SIFS;
extern const double SLOT;
#define AC 4 //number of access categories
extern int staNr;
extern Mac *sta;
StaT fg;
#endif
It doesn't matter whether I use #pragma once, #ifndef #define or both of them. It always results in such errors:
1>d:\studia\mgr\program\edca\edca\globals.h(14) : error C2143: syntax error : missing ';' before '*'
1>d:\studia\mgr\program\edca\edca\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\studia\mgr\program\edca\edca\globals.h(14) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\studia\mgr\program\edca\edca\globals.h(16) : error C2146: syntax error : missing ';' before identifier 'fg'
1>d:\studia\mgr\program\edca\edca\globals.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\studia\mgr\program\edca\edca\globals.h(16) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\studia\mgr\program\edca\edca\mac.h(17) : error C2146: syntax error : missing ';' before identifier 'type'
1>d:\studia\mgr\program\edca\edca\mac.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\studia\mgr\program\edca\edca\mac.h(17) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\studia\mgr\program\edca\edca\edca.cpp(12) : error C2146: syntax error : missing ';' before identifier 'as'
1>d:\studia\mgr\program\edca\edca\edca.cpp(12) : error C2065: 'as' : undeclared identifier
1>d:\studia\mgr\program\edca\edca\edca.cpp(13) : error C2146: syntax error : missing ';' before identifier 'asdf'
1>d:\studia\mgr\program\edca\edca\edca.cpp(13) : error C2065: 'asdf' : undeclared identifier
1>d:\studia\mgr\program\edca\edca\edca.cpp(14) : error C2065: 'asdf' : undeclared identifier
1>d:\studia\mgr\program\edca\edca\edca.cpp(14) : error C2228: left of '.accesspoint' must have class/struct/union
1> type is ''unknown-type''
I always used #ifndef #define directives when I wrote a code in VS 2005 on Windows XP and it worked well. When I try to open some past projects in VS 2005 on my new computer with Windows Vista, I get similar errors. Can anyone explain it to me?
modified on Saturday, April 18, 2009 4:30 PM
|
|
|
|
|
Hi,
always try and solve the first error message first.
It indicates a problem in "extern Mac *sta;" and that is because Mac is not yet defined.
Which is caused by mac.h (which contains the Mac definition) including globals.h before Mac got defined.
Solution candidate 1: remove the include global.h from mac.h (depends on possible unshown content)
Soultion candidate 2: inside mac.h define Mac before including global.h
|
|
|
|
|
Mac is not yet defined, because "Mac.h" was not included in global.h, although I wrote #include "mac.h".
I can't uinderstand why it happens. Why do directives #ifndef, #define stop compiler from including this header. When I delete these directives (#pragma once too) I get multiple inclusion error.
Your propositions are not solutions but problem avoidance. I can't use any of them.
|
|
|
|
|
mass85 wrote: Mac is not yet defined, because "Mac.h" was not included in global.h, although I wrote #include "mac.h".
I can't uinderstand why it happens. Why do directives #ifndef, #define stop compiler from including this header. When I delete these directives (#pragma once too) I get multiple inclusion error.
You need to look at it from the source file (ecda.cpp).
You first include mac.h. The first thing you do in mac.h is to include globals.h. The first thing you do in globals.h is to include mac.h...but mac.h is protected from multiple inclusions. That means that the entirety of globals.h is seen BEFORE the content of mac.h
What I'd do, if I were you, is to remove the #include "globals.h" from mac.h - if you look at it, mac.h has no dependency on anything in globals.h
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
That's a good explanation. Thx.
This code is just the beginning of my project. In the future I will need an access to global objects from Mac class. In fact I will need it in functions of Mac class, so perhaps including globals.h in mac.cpp will be enough and I will be able to delete #include "global.h" from mac.h. In that case these errors won't occur, am I right?
|
|
|
|
|
That's quite correct.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
|
|
|
|
|
Sure. You know best. Who was having a problem?
|
|
|
|
|
I guess you didn't understand me. Whatever.
|
|
|
|
|
|
Please post your question to the managed C++/CLI [^] forum.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
hi
i need a simple class which implements a matrix of mxn elements of complex numbers. i need this class to be a complete one. eg. supports inverse and multiplication to another matrix. i don't need it to be a template one. components are always complex numbers. but if it be, it would be more general.
thx
|
|
|
|
|
Well, you are a software developer, arent you? Code it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yeah, i am, but indeed i've forgotten some mathematical bases!
for example, i've no idea about how to invert a matrix!
|
|
|
|
|
There's the oldie-goldie "Numerical Recipes in C" [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|