|
Hello Sir
This is my source code when i compiled this , its showing some errors ..but i think the code was correct.
this is my source
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, _TCHAR* argv[])
{
static int x __asm("x") = 5;
__asm(
"mov eax, x;"
"shr eax,1;"
"mov x, eax;"
);
cout<<x<<endl;
return 0;
}
error C2143: syntax error : missing ';' before '__asm'<br />
error C2400: inline assembler syntax error in 'opcode'; found '('<br />
error C2400: inline assembler syntax error in 'opcode'; found '('<br />
error C2059: syntax error : ')'<br />
Please Replay !!
Thanks!!
Raju !!!
|
|
|
|
|
I'm not an expert on that field, but I think you should write it this way instead:
__asm {
mov eax, x;
shr eax,1;
mov x, eax;
}
|
|
|
|
|
raju_Code wrote: its showing some errors ..but i think the code was correct.
If it's showing errors then the code cannot be correct.
static int x __asm("x") = 5;
static int x;
You have also encoded your assembly as strings in parenthesis, take the double quotes off, replace the parenthesis by braces, and try again.
|
|
|
|
|
Hi All,
I m building my solutions through command line (devenv.exe).
But the problem is that if build for any project gets failed the script keep running and dosen't stop.How is it possible that i can stop the build file as soon as any error in any project or solution occurs.
Thanx a lot in advance.
It's not enough to be the best, when you have capability to be great....
|
|
|
|
|
When building, you may use Ctrl+Break to stop it.
If you are building using a command line(console), Ctrl+C
|
|
|
|
|
I m not going to sit and watch are there any error every time (since it's used for continuous integration ) i want something that should stop on it's own.
It's not enough to be the best, when you have capability to be great....
|
|
|
|
|
Pavan_Putra wrote: How is it possible that i can stop the build file as soon as any error in any project or solution occurs.
Is there such an option on devenv? What does the documentation say?
|
|
|
|
|
No they don't even talk about it.I had already gone through the documentation and other options there is no such option.
I think there is only one option that you can use, "/Out" parameter to save build log and later check if there were any errors in your build.
I have used the same as there is no option remaining any more.
It's not enough to be the best, when you have capability to be great....
|
|
|
|
|
Pavan_Putra wrote: I had already gone through the documentation and other options there is no such option.
That seems like your answer then. In my experience most of the autogenerated scripts in VS run to completion while logging errors, allowing you to review all the errors at the end of the build.
|
|
|
|
|
can you give examples program of arrays using C language.
|
|
|
|
|
You may find a lot of examples in any good C tutorial or book (even in bad ones, actually...).
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]
|
|
|
|
|
|
in using array, you better read books in your library ok???
hahaha!!
|
|
|
|
|
Have a look at
http://msdn.microsoft.com/en-us/library/ts4c4dw6.aspx
http://www.cplusplus.com/doc/tutorial/arrays/
G.Paulraj
|
|
|
|
|
I create a new MFC class which derived from CEdit Ctrl with the WM_NCPAINT() message. I do nothing in OnNcPaint() method(But I want to do something in it). The Edit control has style of multiline, horizontal , vertical scroll. The scroll bars both are visible if I input enough character . But the problem is that if the edit control redrawed, the scroll bars both are invisible unless I input the character again. How can I keep the scroll bars visible all the time?
Thanks in advance.
|
|
|
|
|
HI all
I am Having list control with datas.
I need for every column a particular item need to coloured...The column can be varied
Kindly help me on this.
|
|
|
|
|
|
Hi,
I allocated a struct from a heap, the struct may be like this one:
struct abc{
int tmp1;
string tmp2;
int tmp3;
}*pabc;
pabc=(abc*)malloc(sizeof abc);
And when I initialize the string(pabc->tmp2="1234"), an "Illegal Pointer" exception occured.
It seems that the size of the string is changed, so I decided to allocate a bigger size.
pabc=(abc*)malloc(sizeof abc+4);
But the error still exists.
sizeof(string("1234")) seems to be 8 instead of 4.
Can anyone help me with this problem?
modified on Sunday, November 22, 2009 11:46 PM
|
|
|
|
|
tyftyftyf wrote: abc->tmp2="1234"
Shouldn't this be pabc->tmp2="1234"
sizeof(string) will give you the size of the internal pointers/counters maintained by the string class.
To get the size of the string use its size() method.
modified on Sunday, November 22, 2009 10:42 PM
|
|
|
|
|
I'm really sorry i mistyped this. And the problem is probably solved by using a pointer to string instead of the string itself.
But I'm still confused about the size problem, for example, a string with 4 characters actually use 8 bytes in memory.Maybe a string contains other parameter variables, not just pure characters.
|
|
|
|
|
Try sizeof(string("abcdefghijklmnopqrstuvwxyz"));
This should also give you 8.
|
|
|
|
|
I see, the string probably itself has a pointer to an array of char.
And I solve the problem by adding:
memset(pabc,0,sizeof(abc));
I realized when using malloc, the memory is not cleared, so the pointer inside the string architect is just a mess, but when setting a value for string, the program found the string struncture is not all zero and considered that the string is already initialized so the program just change the value of the array of char that pointer pointed to.Ofcourse that pointer is just a mess, so "illegal pointer" occured.
If I clear the memory first, the pointer is just zero, so program will initialize it first.
Forgive my poor english....
Thanks!
|
|
|
|
|
As Superman mentioned sizeof(string) returns size of string class and it will return 16 for ANSI and 32 for UNICODE.
In your structure one of a member is a string and you do not know what string size would be until you assign a characters to it.
You are also facing another issue, that you have probably experience. Assigning string to member of pabc structure will cause exception, since you are merely reserving block of memory (including memory for a string) and as a result string member of the abc is not initialized because string constructor is never called.
There is remedy for that but...
pabc = (abc*)malloc(sizeof abc);
memcpy(&pabc->tmp2, &string(), sizeof(string));
pabc->tmp2 = "1234***************************";
Much better and safer is to allocate memory on the heap is to use "new" operator. This will assure that string’s constructor is called and string is properly initialized
pabc = new abc();
pabc->tmp2 = "1234***************************";
Much simpler.
Out of curiosity if you are using MFC why using std string instead of CString class?
JohnCz
MS C++ MVP
modified on Monday, November 23, 2009 10:32 AM
|
|
|
|
|
I see, I should copy a constructed null string first right? I used malloc because I was dealing with a multi-thread program, the thread which allocated and initialized the structure will die far before the structure is useless and should be deleted.So I'm consider using one thread allocate it, and another thread dispose it.
But C++ only allow "new" operator disposing a memory from a thread's local heap.So I used Windows API HeapAlloc and HeapFree, those two can allow two threads allocate and dispose memory from a same heap.
Then I encountered this initializing string problem.To make the code simpler, I wrote malloc instead of HeapAlloc, afterward I found out that these two are almost the same in single thread mode.
I guess I'm still just a beginner in C++.
ps: That program is a console, not MFC. I'd like to use BCB to design GUI. I'm still pretty confused about Windows Messages.
Thanks a lot.
|
|
|
|
|
I have edited my previous post, since code demonstrating new usage was the same (copying I guess).
I do not know if what tool you are using to write your programs. If MSVC and you are using multithreaded runtime libraries, using new is thread safe.
I do not know what function you are using to create thread. Nevertheless if you are concern about memory allocation, allocate your structure in a main thread and pass it as a parameter to a worker thread. After thread terminates, delete object.
I think using new to allocate object is much safer than using other allocation calls.
If you are serious about Windows programming I would suggest writing small Win32 application and see what window procedure does. There is nothing to be confused about windows messages, once you grasp the idea of message loop, dispatching and handling messages. Borland doe not shield you from Windows messages.
I would stay with MS tools and after familiarizing with Windows insides I would suggest using MFC. You can use other higher level languages and packages but they are using separate framework to allow application to run on Windows and make Windows insides transparent to a programmer.
JohnCz
MS C++ MVP
|
|
|
|