|
why do you say it's OK ?
it's not.
void A( int channel)
{
}
int _tmain(int argc, _TCHAR* argv[])
{
A();
return 0;
}
1>c:\temp\fargs.cpp(11) : error C2660: 'A' : function does not take 0 arguments
|
|
|
|
|
But in the program,
our system.
It works.
I tested it. just the caller.h:
extern void A(void);
I debugged the code, it stepped into the A(i);
in fact, only one A() function in the program.
|
|
|
|
|
what compiler are you using?
at best, i would think the behavior is undefined. the function is going to try to find a parameter, somewhere. maybe it pulls some random garbage off the stack where it expects a parameter to be, or maybe your compiler puts variables into certain registers (and so the function will just grab random garbage out of a register).
|
|
|
|
|
It's a GHS compiler.
An embedded project.
|
|
|
|
|
It's possible that the compiler patches the call with a default argument.
What is the value in channel? I'm guessing it is 0.
Anyway this is not valid in standard C and will surely not compile in GCC or Microsoft C compilers.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
It looks like you have two different versions of A. But then you are not showing us the complete code.
|
|
|
|
|
You shoud correct your caller.h to have the correct prototype for A(). Then #include caller.h in both where you define A() and where you invoke it.
This "works", due to C calling conventions, where the caller is responsible for pushing and popping arguments off the stack. In your case the caller doesn't push anything on the stack. When A() executes it will use whatever values are on the stack as its parameters, which in this case could be any value at all.
|
|
|
|
|
Further to this, in C the declaration void f(); does not declare a function with no parameters, but declares a function with an unknown number of parameters. If you know that a function takes no arguments, you should prototype it as void f(void); . Otherwise, the compiler will happily let you do the following:
void f();
int main(void)
{
f();
f(15);
f("Hello", "World");
}
Using gcc I can compile the above with -Wall -Wextra, and get no warnings. If I add -Wstrict-prototypes, I do get the warning "function declaration isn’t a prototype [-Wstrict-prototypes]. If you're using MS-VSC, there's probably a similar warning flag that you can use.
|
|
|
|
|
There are only two options...
1. There is a function declarations in an other (probably h) file with a default value
void A(int c = 0);
int main()
{
A(1);
}
void A(int c)
{
}
2. There is an overloaded version of A somewhere else
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: void A(int c = 0); Do C functions allow this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Of course not - but that only means that OP does not know the difference between C and C++
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Kornfeld Eliyahu Peter wrote: Of course not Right. So then why would you suggest to him that such a function was a possible explanation for his question?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
As I told - I'm not sure OP knows the difference between C and C++ and what language is the project in (a leftover from someone else probably)...
Taking in count, that it is part of code from a working system, and that the mentioned compiler can compile both C and C++, and the abilities of C and C++ I put my bet on OP's mistake...
In fact if we stick to the C version, it can not work at all (C has only the varargs option, but that forces at least one named parameter, which we have not)...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Hi Everyone,
I have a application which needs to read a file of size 113MB and stores each row data into a class object which is in turn stored in a std::map<int, cmyclassobject="">. Running it in 32-bit 4 GB RAM , the "Out of Memory" error triggered. After a observation , I felt that the RAM is not sufficient, so now I tried it in 64-bit 8GB RAM system but still the same exception is thrown. Can anyone help me in finding what exactly might be problem and how it can be overcome?
Thanks in Advance!!
|
|
|
|
|
Do you NEED to hold all of the data in memory concurrently?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
yes. the data read from the file to be stored internally.
|
|
|
|
|
I understand that much from your initial post. But does it all need to me in memory concurrently? It's highly unlikely that it does, but only you can be the ultimate judge of that.
What exactly are you doing to/with the data? Maybe an on-disk solution can be suggested.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Thank you for the suggestion. I could have tried that if all data were not required and could have read only the required data from the file and store it in memory. But here the need is, after loading of file, it shall take inputs from user either to process all the data or required data, if its all data then it has to have all the data stored in memory.
|
|
|
|
|
divya03 wrote: I tried it in 64-bit 8GB RAM system but still the same exception is thrown Did you rebuild for a 64 bit target?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Ya I've rebuild in 64 bit target and run the program in 64 bit system.
|
|
|
|
|
Perhaps there is something useful in this thread[^]. Do you have an estimate of the amount of memory needed?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
118Mb isn't all that big. You could easily hold it in memory. The map is costing you the size of the class plus about four pointers worth of storage for each entry. Perhaps your class stores the data very inefficiently. Perhaps you have a bug on reading in the data, like not recognizing end of file and adding endless entries until you run out of memory. Perhaps you have a memory leak.
- How many rows are in the file? You can easily build a function to count rows using the current function that inputs data, but without saving the data.
- How many rows are read in at the time the out-of-memory exception occurs? This and the last question might tell you if you had a bug inputting the data.
- Are you using std::string to hold any of the row data, because memory costs can really add up when using std::string.
Maybe your representation is too expensive for the memory you have. You could approach this problem by reading in the file as a block, and building a data structure that puts pointers into the file block for each line, and then parse out a single line when you need one.
|
|
|
|
|
Total number of rows are around 7 lakhs. The out of memory is occurring after around 4lakhs rows are read and when the memory in task manager shows around 700000k by the application. Yes std:string is used as a member variable of class object.
|
|
|
|
|
On average, std::string allocates enough memory to hold 1.5x the size of the actual string. (This is a rule of thumb), plus 2 pointers of overhead. This could be your problem, depending how many strings you have per row. Depending how you've written your data structure, it's quite likely that you have really exhausted memory. You need to rethink the problem so to solve it using less memory.
|
|
|
|
|
Are you sure the memory is actually the issue and you aren't hitting the class object limit. From memory the allocation just starts failing when you hit the 10,000 limit. Adding more memory doesn't help because it isn't the problem in the first place, you just can't allocate any more objects. Easy to check count objects as you create them and see what count you get to.
In vino veritas
modified 13-Aug-17 1:04am.
|
|
|
|