I think I got part of the answer - I am mixing logical operations with math so that is why the first #define works ( compare to value) AFTER I added brackets.
#define PIO_SODR (SAM_MSB << 16 | SAM_LSB + PIO_OFFSET) now passes the value test OK
#define PIOA_SODR (PIO_SODR + PIO_OFFSET)
But the additional offset does not work, but I am getting closer.
Thank for your help.
And it also helps to check if my #define(s) are not duplicated somewhere else !!!
Mainly because the "core" program is build using defines and I am still not too comfortable using enum.
BTW after I "solved" this problem I have decided to "improve" on on it a got stuck again.
Life is fun.
I can only agree with Carlo on this. More generally, whenever there is a suitable way to use standard language features instead of #define, use that standard language feature. Even if it means you need to type more!
Modern editors offer autocompletion that makes typing effort a non-argument! Moreover, code riddled with #define macros is much harder for editors to interpret, preventing it from offering correct and complete autocompletion lists. Therefore the use of #define has the very real potential to actually increase the typing effort by hamstringing the editors capabilities!
Besides, as you've already stated, #defines will just keep tripping you up. Most of the time it is due to their entire lack of context-related syntax checking at the time of writing. And sometimes it is because your macro name conflicts with another non-macro symbol in some totally unrelated part of the code - that latter issue will lead to obscure errors that can keep you busy for days. I am speaking from my own experience.
Therefore: save time - do not use #define unless there is no other way to achieve the intended results. And if you do, don't place these macros in a header that gets included in unrelated source files - either put them right into the source file that needs them, or, if there are multiple source files that need them, put the macros in a separate header just for that purpose.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
I would like to know how to send a text file from C to java, in which java has to receive the file and send it back to C. I have developed the code, but i am facing error in the receive function
int size, read_size, stat, packet_index;
char send_buffer, read_buffer;
packet_index = 1;
text = fopen("/home/sosdt009/Desktop/character3.txt", "r");
if (text == NULL)
printf("Error Opening text File:");
printf("Getting text Size:\n");
fseek(text, 0, SEEK_END);
size = ftell(text);
fseek(text, 0, SEEK_SET);
printf("Total text size: %d \n", size);
//Send text Size
printf("Sending text Size:\n",size);
send(socket, (void *)&size, sizeof(size), 0);
stat = recv(socket, read_buffer, 1024, 0);
}*/while(stat < 0)
printf("Socket data:%s \n", read_buffer);
//Read from the file into our send buffer
read_size = fread(send_buffer,1,sizeof(send_buffer),text);
printf("The size of send buffer:%c \n",send_buffer);
printf("The read size value is :%d \n", read_size);
//Send data through our socket
stat = send(socket, send_buffer, read_size, 0);
printf("The send size value is: %d \n", size);
printf("The read size value is: %d \n", read_size);
} while (stat < 0);
printf("Packet %d, sent %d bytes.\n", packet_index, read_size);
//Zero out our send buffer
tsize = tsize+read_size;
printf("The tsize value is:%d \n",tsize);
printf("The connection is transferred to received text: \n");
printf("Text successfully send:\n");
int receive_text(int socket)
int buffersize = 77,recv_size=0,read_size = 1, write_size,size;
textnew = fopen("/home/sosdt009/Desktop/receivednew.txt", "a");
if (textnew == NULL)
printf("Error has occurred, text file could not be opened \n");
//Loop while we have not received the entire file yet
while(read_size > 0)
//ioctl(socket, FIONREAD, &buffersize);
printf("The Buffersize is :%d\n",buffersize);
printf("The size of socket is:%d\n",socket);
//We check to see if there is data to be read from the socket
if (buffersize > 0)
printf("Buffersize value is :%d\n", buffersize);
pBuf = malloc(sizeof(b));
printf(errnom, "Memory Error Cannot Allocate!\n");
//read_size = read(socket,pBuf,buffersize);
//read_size = fread(pBuf,buffersize,1,textnew);
read_size = recv(socket,pBuf,sizeof(pBuf),1);
printf("Read size value is :%d \n",read_size);
printf("Buffersize value is:%d \n",sizeof(pBuf));
/*if (read_size < 0)
printf("Data not written to the file:\n");
//Write the currently read data into our text file
//write_size = write(textnew,read_size,pBuf); //using write function
write_size = fwrite(pBuf,1,sizeof(pBuf),textnew);
printf("Write size value is :%d \n",write_size);
printf("Buffer size value is :%d \n",sizeof(pBuf));
//Increment the total number of bytes read
recv_size += read_size;
printf("Received size value is:%d \n",recv_size);
printf("Read size value is :%d \n",read_size);
printf("Text Successfully Received:\n");
int main(int argc,char *argv)
struct sockaddr_in server;
A common solution to access MFC objects from other threads is posting user defined messages. Then the manipulation of the object occurs inside the thread that owns the MFC object. If your thread is a worker thread see the CP article Using Worker Threads[^] for examples.
With the new great OS -- 10 -- we're seeing something odd.
Running our installer is not shutting down our app.
We do receive the WM_QUERY_ENDSESSION and we do reply with TRUE ( ok to shutdown )
But, upon receiving the WM_ENDSESSION we receive a FALSE (don't shutdown).
Somewhere between the QUERY and the END -- "someone" is saying NO to this.
How does one go about debugging this sort of thing?
I've used SPY++ but am not finding it to be the most useful tool, except to confirm what I knew in code. SPY is not telling me who sends the QUERY. If I could figure out where these messages are coming from, maybe I could watch the conversations taking place around this transaction.
-- in previous versions of Windows this was not an issue -- it worked like we would expect. But Windows10 is telling me not to end my session.
Peter Weyzen<br />
Staff Engineer<br />
<a href="http://www.soonr.com">soonr.com -- PC Power delivered to your phone</a>
hi i had learn c++ and something about the framework Qt but the problem that the Qt is not used for building apps smartphone like C# or JAVA !!
so do u advice me to leave c++ and Qt and start with C# or JAVA ??
please i need your Advice Thank you
Now. I am getting focus on first button of toolbar. I clicked SPACEBAR and this button get pressed. It open a dialog , after my operation I closed it.
After that, Unfortunately second button get activated. I pressed spacebar again.It will pressed that button and called related function , which will open another dialog. After my operation, I closed it .
Now the focus went to First button. According to project requirement the focus must retain to the last clicked button. I checked in project code, nowhere first button getting activated explicitly.
I am working on a legacy Windows app written in Win32.
There's a checkbox in the screen and i call the SetFocus() function to have the focus on it. I know that it works as far as setting the focus, because now i can use space button in keyboard to check and uncheck the checkbox.
But the problem is, when a control get's the focus, it's supposed show a broken rectangle around it. In my case this broken rectangle is not drawn/shown all the time. Sometimes it shows the broken rectangle and some times it doesn't.
I need to show some visual indication to user that this checkbox has the focus. I tried using WM_CTLCOLORSTATIC, but that creates some painting issues in the window.
So am looking for a simpler solution, by which i could show some visual indicator to user that this checkbox is having focus.
Like changing the text color or background color or even force draw a broken rectangle.
But i have no idea how to do this without using the WM_CTLCOLORSTATIC.
Is there a easier way to show some sort of visual indication on a checkbox in Win32?
There's a bunch of good texts listed in this[^] thread.
"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
Last Visit: 24-May-20 13:58 Last Update: 24-May-20 13:58