|
void *x;int *a1=a,*b1=b;
x=(void *) a1;a1=b1;b1=(int *) x;
That just makes no sense, x should be int* the same as a and b .
|
|
|
|
|
As I am sure this is homework I won't give you the answer, what I will tell you is the problem with the typecast
Using the dereference operator (the *) is like mathematics there is an order to things just like in mathematics.
If I gave you 2 + 3 * 4 and you wanted the add before the multiply you need brackets (2 + 3) * 4 the mult carries higher precedence normally.
Same problem happens in dereference operator when using arrays
double **a;
*a[2] has two possible breakdowns so lets use brackets (*a)[2] or *(a[2])
*a[2] is actually equivalent to the latter *(a[2])
I bet that is not what you were expecting and reading it as
Your code doesn't do anything like what your text comments say because you are missing brackets. You need the dereference completed prior to the array use and (*a)[2] is the correct use for you.
Lets give you a simple code
double myArray[6] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
double *p = &myArray[0];
double d = p[3];
double **q = &p;
double s = (*q)[3];
double t = *q[2];
Does that last line look familiar?
It is the same if the you are derefencing an object or a class
*a.xyz may naively be intended as (*a).xyz or *(a.xyz)
*a->xyz may naively be intended as (*a)->xyz or *(a->xyz)
So look up and learn the precedence order of dereferencing and if you want the other USE BRACKETS. It's actually good practice to always use brackets if you are dereferencing complex items so you know for sure what the order will be be, you do the same with long chains with mathematics. It's a normal gotcha to not dereference what you think you are on complex items because of dereference precedence order (you can't just read it left to right and expect that order).
In vino veritas
modified 21-Sep-16 1:38am.
|
|
|
|
|
|
Can anyone suggest me, how to implement program that break (.png) image in two equal part?
|
|
|
|
|
|
If you're able to, you really should consider leveraging c++ for this task.
Doing so allows you to use functionality built into windows for well over a decade - GDI+.
GDI+ allows one to read formats windows supports natively, also including methods that facilitate the saving of bitmap images to files on disk.
|
|
|
|
|
He has asked for C and he said nothing about Windows so why bring up Windows/GDI ... You need to remember not everything that is requested is for a PC and often not on Windows.
It's highly possible he doesn't have a C++ compiler available or even as an option for what he is working on. There is a very large embedded industry out there and almost none of those micro-controllers and processors have a C++ compiler available.
Don't make assumptions about what he is doing.
In vino veritas
|
|
|
|
|
Simple. He didn't explicitly say they would be no good. CodProject is, as you're no doubt fully aware, an MS-centric site. It's also not uncommon for new members to be less explicit than would be beneficial.
I don't need to remember anything pal. I'm fully aware that plenty of articles here are for Arduino projects.
No-poop sherlock. I've spent time in it myself.
Go back and read my post, ya dolt. Here, I've saved you the trouble. I even highlighted the important parts you seemed to have made your own assumptions about.
If you're able to, you really should consider leveraging c++ for this task.
The only assumption I made was that all offerings of help made in good faith would be gratefully received - not necessarily useful, but received gratefully all the same.
Go and get a dog up ya
|
|
|
|
|
I have no idea why you feel the rant is necessary .. I have referred it to admin
I found your comment strange for the following reasons, so we are clear
1.) The original PNG library was written in C and is still maintained (20 years so far)
2.) It's dubious there is any advantage on converting PNGLIB to C++ you are just likely to get bugs any C++ compiler can compile PNGLIB anyhow
3.) The OP said nothing about windows
4.) Even if you are on windows the GDI+ does not support PNG because it is licenced .. SEE => PNGLIB.
Even IPicture which support JPG and GIF does not support PNG. So you would still have to write your own GDI+ extension code.
There is no malice intended, I just think your advice was misguided for the above reasons. Now if I am in error on any of those points then please let me know.
In vino veritas
modified 20-Sep-16 6:36am.
|
|
|
|
|
You might use a library, or, as others suggested, GDI+ . The natural way for accessing GDI+ is using C++ . However it exposes also a (not recommended) flat API[^].
|
|
|
|
|
Same comment as above the poster said nothing about being on Windows. Why would you assume he has it available? He asked to split a PNG file with C code that was it.
In vino veritas
|
|
|
|
|
Because this is the C/C++/MFC forum. It is just a guess, anyway.
|
|
|
|
|
Okay so in C you will find references to libpng which was done for a computer book all over the internet, it is a platform-independent library that contains C functions for handling PNG images that is 20 years old. Technically the code is ANSI C (C89) which should run on most C compilers even those for micro-controllers.
It isn't bad and easily understandable. You will often find more up to date conversion of the original code
but it's more often you will run across the read implementation than the write.
The code to use the png library isn't hard as you will see
A simple libpng example program[^]
You download the png library from the pnglib homepage
libpng Home Page[^]
There are manuals and "howto" instructions and pages there.
In vino veritas
modified 19-Sep-16 13:29pm.
|
|
|
|
|
We are using the Carlos Antollini ado classes in our C/C++ program and when I try to close the database it hangs. The function never returns. I cannot figure out why. Anyone have any ideas?
m_pProjectDatabase declared as:
CADODatabase* m_pProjectDatabase;
if (m_pProjectDatabase != nullptr)
{
m_pProjectDatabase->Close();
}
This calls the ado2 function:
void CADODatabase::Close()
{
try
{
if(IsOpen())
{
if(m_doxCatalog.m_pCatalog != NULL)
{
_ConnectionPtr pConn = m_doxCatalog.m_pCatalog->GetActiveConnection();
pConn->Close();
}
}
}
catch(CString ex)
{
throw;
}
catch(_com_error &e)
{
dump_com_error(e);
}
catch(...)
{
throw (CString)"Unexplained Error in CADODatabase::Close";
}
}
and from there, nothing. Off into cyberspace never to be seen again.
|
|
|
|
|
Did you debug this CADODatabase::Close() code?
|
|
|
|
|
I have 2 vc 630 both of them the drink section is inop. I ran a motor count and it recognize the first 20 motors and not the drink section everything seem to be plugged in that I can see James
|
|
|
|
|
Sorry, we are software developers, primarily. We are not vending machine support people.
|
|
|
|
|
the muffler bearings need more walnut oil
|
|
|
|
|
I think some tickets to a seminar by Tony Robins sounds like just what your machines need.
|
|
|
|
|
Call machine support.
I think nothing can be done without physical access to the machines.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
I receive an old project developing with COM and C++, this project throw much exception for the INVALID_POINTER,
I guess maybe the pointer is release, but then use this pointer.
Is there anyway to check where the memory leak and where the pointer is released?
|
|
|
|
|
Use the debugger .. you are a programmer!!!!!!!
When it breaks it will give you the pointer that is involved ... now look at all code that uses the pointer.
Also actually bother to look at any warning the compiler is spitting out.
The other thing you can have done is forgot to initialize the pointer and you are assuming it is zero.
pointer p;
pointer p = 0;
This can give the weird behaviour that in debug mode the code will work but in release mode it will crash. The reason is in debug mode the compiled code takes the time to zero all variables for you and so both codes act the same, in release mode it will not zero variables and "p" will be initialized at some garbage value.
You can generally pick this problem off by turning your warning level up to 4 on the compiler ... it will spit a warning ... "Possible use of uninitialized pointer"
In vino veritas
modified 9-Sep-16 1:12am.
|
|
|
|
|
Well, a memory leak is the opposite thing and happens when a pointer goes out of scope or is overwritten before the allocated memory was released.
What you have is a faulty lifcycle management. You can't release an object and then try to use it again. Your program must make sure that pointers are initialized before being used and also that those pointers are not forgotten or overwritten.
Begin with setting all pointers to NULL immediately after releasing the memory. This way you can at least check wether the pointer is NULL or contains a valid pointer before using it. To completely solve it, you should implement a better lifecycle management for your objects.
The language is JavaScript. that of Mordor, which I will not utter here
This is Javascript. If you put big wheels and a racing stripe on a golf cart, it's still a f***ing golf cart.
"I don't know, extraterrestrial?"
"You mean like from space?"
"No, from Canada."
If software development were a circus, we would all be the clowns.
|
|
|
|
|
Running with a memory leak detector can help?
|
|
|
|
|
According to the documentation included with this snippet I should be able to replace the placeholder function with my own.
I am not knowledgeable enough to decipher what exactly is the code trying to accomplish and how to replace it with real function.
A reference would also work, but since I have no idea what is this called I do not know what to Google for. Since this is not working code, code tags were not used.
Appreciate your help
Vaclav
/**
* SysTick hook
*
* This function is called from SysTick handler, before the default
* handler provided by Arduino.
*/
static int __false() {
// Return false
return 0;
}
int sysTickHook(void) __attribute__ ((weak, alias("__false")));
|
|
|
|