It's the same example.
It's the same example.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hello All,
I keep fixing misaligned statements as Salem suggested.
But now I have some statement I can't get working
On line number 112 I got this while compiling -
This source is looking like this:Code:RTCPUtilitiesLib/RTCPSRPacket.h: In member function `void RTCPSRPacket::SetSSRC(UInt32)': RTCPUtilitiesLib/RTCPSRPacket.h:112: warning: cast from `char (*)[132]' to `UInt32*' increases required alignment of target type
Code:109 inline void RTCPSRPacket::SetSSRC(UInt32 inSSRC) 110 { 111 // Set SSRC in SR 112 ((UInt32*)&fSenderReportBuffer)[1] = htonl(inSSRC);
I've tried to fix this (112) line with:
UInt32 temp1; memcpy(&temp1, htonl(inSSRC), sizeof temp1); (&fSenderReportBuffer)[1]=&temp1;
and with -
UInt32 temp1; memcpy(&temp1, &htonl(inSSRC), sizeof temp1); (&fSenderReportBuffer)[1]=temp1;
But still I get these messages while compiling:
Any help/suggestions on how to fix this misaligned statement?Code:RTCPUtilitiesLib/RTCPSRPacket.h: In member function `void RTCPSRPacket::SetSSRC(UInt32)': RTCPUtilitiesLib/RTCPSRPacket.h:112: error: incompatible types in assignment of `UInt32*' to `char[132]'
Last edited by biggyK; 06-22-2006 at 01:38 AM.
Guessing that fSenderReportBuffer is
char fSenderReportBuffer[132];
I would do
Code:unsigned long temp = htonl(inSSRC); memcpy ( &fSenderReportBuffer[sizeof(UInt32)], &temp, sizeof(temp) );
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Thank you very much Salem.
Your solution is working!!!
Salem ,
Sorry for bothering with the same issue, but...
As you can see on the lines 112,115,119...
We have different values insideCode:112: ((UInt32*)&fSenderReportBuffer)[1] = htonl(inSSRC); 115: ((UInt32*)&fSenderReportBuffer)[8] = htonl(inSSRC); 119: ((UInt32*)&fSenderReportBuffer)[(fSenderReportSize >> 2) + 1] = htonl(inSSRC);
fSenderReportBuffer[here is the value that changes on all the lines]
Where should I insert the appropriate change so it would meet your solution for every line:
Code:unsigned long temp = htonl(inSSRC); memcpy ( &fSenderReportBuffer[sizeof(UInt32)], &temp, sizeof(temp) )
Hi,
Should this code
look like this on line 119? :Code:unsigned long temp = htonl(inSSRC); memcpy ( &fSenderReportBuffer[sizeof(UInt32)], &temp, sizeof(temp) );
or like this:Code:unsigned long temp = htonl(inSSRC); memcpy ( &fSenderReportBuffer[(fSenderReportSize >> 2) + 1], &temp, sizeof(temp) );
Code:unsigned long temp = htonl(inSSRC); memcpy ( &fSenderReportBuffer[sizeof(UInt32)], &temp, sizeof(temp) ); (&fSenderReportBuffer)[(fSenderReportSize >> 2) + 1]=temp;
Last edited by biggyK; 06-26-2006 at 06:53 AM.
> ((UInt32*)&fSenderReportBuffer)[1] = htonl(inSSRC);
Recall this line became
memcpy ( &fSenderReportBuffer[sizeof(UInt32)], &temp, sizeof(temp) );
More generally, I could have written
memcpy ( &fSenderReportBuffer[sizeof(UInt32)*1], &temp, sizeof(temp) );
where the 1 is the subscript you would like had the array been a proper array of UInt32.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Salem,
Thanks for the explanations.
Hi,
Continuing to fix misaligned statements and need some help.
1) I got this error:
Server.tproj/RTCPTask.cpp:95: warning: cast from `UDPDemuxerTask*' to `RTPStream*' increases required alignment of target type
In file included from Server.tproj/RTPSessionInterface.h:41,
from Server.tproj/RTPSession.h:48,
from Server.tproj/RTPSession.cpp:36:
This is how the source line looks like:
I've tried to fix it with -Code:95 RTPStream* theStream = (RTPStream*)theDemuxer->GetTask(theRemoteAddr, theRemotePort);
or this -Code:struct RTPStream temp; memcpy (&temp, theDemuxer->GetTask(theRemoteAddr, theRemotePort), sizeof temp); RTPStream* theStream =&temp;
But I keep getting compilation errors like these:Code:RTPStream temp(theDemuxer->GetTask(theRemoteAddr, theRemotePort)); RTPStream* theStream =&temp;
That can I do here?Code:Server.tproj/RTCPTask.cpp: In member function `virtual SInt64 RTCPTask::Run()': Server.tproj/RTCPTask.cpp:95: error: no matching function for call to `RTPStream::RTPStream(UDPDemuxerTask&)' Server.tproj/RTPStream.h:57: note: candidates are: RTPStream::RTPStream(const RTPStream&) Server.tproj/RTPStream.h:66: note: RTPStream::RTPStream(UInt32, RTPSessionInterface*) make: *** [Server.tproj/RTCPTask.o] Error 1
2) Another problem is like this:
I got htis error:
This is how the source looks like -Code:Server.tproj/RTPSessionInterface.cpp: In static member function `static void* RTPSessionInterface::TimeConnected(QTSSDictionary*, UInt32*)': Server.tproj/RTPSessionInterface.cpp:277: warning: cast from `QTSSDictionary*' to `RTPSessionInterface*' increases required alignment of target type Server.tproj/RTPSessionInterface.cpp: In static member function `static void* RTPSessionInterface::CurrentBitRate(QTSSDictionary*, UInt32*)': Server.tproj/RTPSessionInterface.cpp:287: warning: cast from `QTSSDictionary*' to `RTPSessionInterface*' increases required alignment of target type Server.tproj/RTPSessionInterface.cpp: In static member function `static void* RTPSessionInterface::PacketLossPercent(QTSSDictionary*, UInt32*)': Server.tproj/RTPSessionInterface.cpp:298: warning: cast from `QTSSDictionary*' to `RTPSessionInterface*' increases required alignment of target type
Code:277 RTPSessionInterface* theSession = (RTPSessionInterface*)inSession; 287 RTPSessionInterface* theSession = (RTPSessionInterface*)inSession; 298 RTPSessionInterface* theSession = (RTPSessionInterface*)inSession;
I've tried to fix it like this -
But keep getting errors for these fixes:Code:277 struct RTPSessionInterface temp; memcpy (&temp, inSession, sizeof temp); RTPSessionInterface* theSession =&temp; 287 struct RTPSessionInterface temp1; memcpy (&temp1, inSession, sizeof temp1); RTPSessionInterface* theSession =&temp1; 298 struct RTPSessionInterface temp2; memcpy (&temp2, inSession, sizeof temp2); RTPSessionInterface* theSession =&temp2;
How can I fix these errors here?Code:Server.tproj/RTPSessionInterface.cpp: In static member function `static void* RTPSessionInterface::TimeConnected(QTSSDictionary*, UInt32*)': Server.tproj/RTPSessionInterface.cpp:277: error: cannot declare variable `temp' to be of type `RTPSessionInterface' Server.tproj/RTPSessionInterface.cpp:277: error: because the following virtual functions are abstract: CommonUtilitiesLib/Task.h:94: error: virtual SInt64 Task::Run() Server.tproj/RTPSessionInterface.cpp: In static member function `static void* RTPSessionInterface::CurrentBitRate(QTSSDictionary*, UInt32*)': Server.tproj/RTPSessionInterface.cpp:287: error: cannot declare variable `temp1' to be of type `RTPSessionInterface' Server.tproj/RTPSessionInterface.cpp:287: error: since type `RTPSessionInterface' has abstract virtual functions Server.tproj/RTPSessionInterface.cpp: In static member function `static void* RTPSessionInterface::PacketLossPercent(QTSSDictionary*, UInt32*)': Server.tproj/RTPSessionInterface.cpp:298: error: cannot declare variable `temp2' to be of type `RTPSessionInterface' Server.tproj/RTPSessionInterface.cpp:298: error: since type `RTPSessionInterface' has abstract virtual functions make: *** [Server.tproj/RTPSessionInterface.o] Error 1
Thanks in advance for your replies.
Whoa! Far too many casts! You're hiding the real errors.
For example, demuxer->GetTask obviously returns a UDPDemuxerTask*. Why do you try to asssign it to an RTPStream*? Is RTPStream a subclass of UDPDemuxerTask? Then use dynamic_cast. Otherwise you're just doing something totally illegal.
Ecactly the same issue in your second problem. The source is QTSSDictionary*, the target RTPSessionInterface*. What makes you think you can just assign them?
C++ is strongly typed for a reason.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
This is not my code.
This is part of DSS (Darwin Streaming Server of Apple).
I'm just trying to fix some misaligned statements, which preventing to run DSS on my architecture.
I'm not a C++ programmer, just have a basic knowledge and trying to get some help/advice here.
Hello Salem,
I'm really lost with code (I've posted above on 07-08-2006, 10:31 AM).
Could you please review and tell/recommend me how to deal with it?
> Could you please review and tell/recommend me how to deal with it?
You really need to get in contact with the authors / maintainers at this point.
> warning: cast from `UDPDemuxerTask*' to `RTPStream*' increases required alignment of target type
Fixing alignment of say UINT32 is one thing, fixing class pointers is another.
Especially if both things are part of the same class heirarchy, and up/down casting is supposed to do "the right thing" by the rules of C++.
Understanding how those classes are supposed to interact is far more work than I'm prepared to take on at the moment - maybe someone else would help you if you'd care to post an announcement in the projects and recruitment board (if the author isn't willing to help). This is sounding like a significant task all of a sudden.
If this isn't happening, then something serious has gone wrong, and the approach so far just isn't going to work anymore IMO.
Are you still getting bus errors when you try and run what you've produced so far ?
That is, have you done enough so that it now runs when you turn off the alignment warning?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Hello Salem,
Thanks for your reply.
I still get "Bus Errors".
Seems to me that I should install Solaris 10 on that machine (DSS reported to compile and run on that OS).
Thanks for all your help