|
I totally agree with Dave Kreskowiak 
|
|
|
|
|
I respect your opinion.
cuique suum...
|
|
|
|
|
I agree with this mostly, but since I'm not a real programmer I use vim.
|
|
|
|
|
I've to admit I use vim too. 
|
|
|
|
|
The first question is whether you have done ANY programming. If not, I suggest finding an "Fundamentals of Computers" class at your local community college or online (my kids took a class similar to the following: Free Online Course: Computer Science 101 from Stanford OpenEdx | Class Central[^])
FWIW, my youngest son scoffed at a class just like the above, went straight to CS 101 and was overwhelmed. He was getting his homework done, but not understanding any of it. Like me, just saying something was a variable wasn't good enough--what really was a variable? Unlike me, after the above class, he decided computer programming wasn't for him. To be honest, it probably isn't, but my youngest daughter aced that class and would be a good computer. Alas, she shows no interest.
From there, I agree with leon; get Visual Studio Community Edition. Your intent is to learn programming. If you are on Linux, get CLion.
|
|
|
|
|
I took and completed with a B an intro to programming course once. I think I have a good grasp of the very basics. Now I want to build on that knowledge and begin learning as much as possible.
|
|
|
|
|
One thought that's just occurred to me is that you could learn C while programming an Arduino. It's technically a superset of C (it has a string type) but if you buy a starter kit[^] you'll have a set of tutorials to complete that may (or may not) help you to learn as you go. Some people say they find it easier to stay motivated when they have some tangible result.
I can't really say how good the learning tutorials are though, because when I got my first Arduino I already knew a reasonable amount of C so I didn't really need to learn any language specific stuff from the documentation - just hardware specifics.
|
|
|
|
|
I am trying to implement coroutines in c++ (I had to reinvent the wheel for my project).
coroutine.h
class coroutine {
public:
void (*action1)(int);
Stack local_stack;
coroutine(void (*action)(int ), int id); ///< will create coroutine
~coroutine();
static void yield();
};
coroutine.cpp
coroutine *global_coro;
fcontext_t context_array[2];
coroutine :: coroutine(void (*action)(int), int id)
{
global_coro=this;
action1=action;
fcontext_t f_ctx = make_fcontext(global_coro->local_stack.local_stack, 1000, global_coro->action1);//Save the current context of coroutine for the sake of making switch context.
// make_fcontext is in .S file taken from boost::context
context_array[0]=f_ctx; // Global Array to store the coroutine context so that i can switch the context
}
coroutine::~coroutine(){}
void coroutine::yield(){
transfer_t tr = jump_fcontext(context_of_current_corotine, context_of_next_coroutine ); //Also in .S file
Following is my stack class which allocates a block of memory to every coroutine from a global Memory pool
stack.h
extern MemoryPool memPoolObj;
class Stack {
public:
void *local_stack;
MemoryPool& m_memPool=memPoolObj;
Stack();
~Stack();
};
Stack.cpp
#include "Stack.h"
MemoryPool memPoolObj;
Stack::Stack() {
auto *local_stack= m_memPool.Allocate();
}
Stack::~Stack() {}
Context.h
typedef void* fcontext_t;
struct transfer_t
{
fcontext_t fctx;
void * data;
};
extern "C"
transfer_t jump_fcontext( fcontext_t const to, void * vp);
extern "C"
fcontext_t make_fcontext( void * sp, std::size_t size, void (* fn)( int) );
Main.cpp
#include "coroutine.h"
void workPackage(int id){
printf("Coroutine with id %d is called\n", id);
coroutine::yield();
printf("Coroutine with id %d is resumed after first yield\n", id);
coroutine::yield();
printf("Coroutine with id %d is resumed after second yield\n", id);
}
int main() {
coroutine Coro1(workPackage, 1);
coroutine Coro2(workPackage, 2);
printf("Main is finished \n");
}
My program compiles but gives segmentation fault during execution. Valgrind gives the following information and i am not able to solve the problem. I will provide the assembly file also if needed. Any help would be appreciated
Use of uninitialised value of size 8
==24145== at 0x10922B: make_fcontext (in /home/user1/eclipse-workspace/coroutines/Debug/coroutines)
==24145== by 0x10912D: main (main.cpp:32)
==24145==
==24145== (action on error) vgdb me ...
==24145== Continuing ...
==24145== Invalid write of size 8
==24145== at 0x10922B: make_fcontext (in /home/user1/eclipse-workspace/coroutines/Debug/coroutines)
==24145== by 0x10912D: main (main.cpp:32)
==24145== Address 0xffffffffffffffe8 is not stack'd, malloc'd or (recently) free'd
|
|
|
|
|
Where is the code for make_fcontext , which is shown as the place where the error occurs?
|
|
|
|
|
My project structure in eclipse is as follows
Coroutines
Src
Debug
Code for make_fcontext is in src folder in file "make_x86_64_sysv_elf_gas.S"
.text
.globl make_fcontext
.type make_fcontext,@function
.align 16
make_fcontext:
/* first arg of make_fcontext() == top of context-stack */
movq %rdi, %rax
/* shift address in RAX to lower 16 byte boundary */
andq $-16, %rax
/* reserve space for context-data on context-stack */
/* on context-function entry: (RSP -0x8) % 16 == 0 */
leaq -0x40(%rax), %rax
/* third arg of make_fcontext() == address of context-function */
/* stored in RBX */
movq %rdx, 0x28(%rax)
/* save MMX control- and status-word */
stmxcsr (%rax)
/* save x87 control-word */
fnstcw 0x4(%rax)
/* compute abs address of label trampoline */
leaq trampoline(%rip), %rcx
/* save address of trampoline as return-address for context-function */
/* will be entered after calling jump_fcontext() first time */
movq %rcx, 0x38(%rax)
/* compute abs address of label finish */
leaq finish(%rip), %rcx
/* save address of finish as return-address for context-function */
/* will be entered after context-function returns */
movq %rcx, 0x30(%rax)
ret /* return pointer to context-data */
trampoline:
/* store return address on stack */
/* fix stack alignment */
push %rbp
/* jump to context-function */
jmp *%rbx
finish:
/* exit code is zero */
xorq %rdi, %rdi
/* exit application */
call _exit@PLT
hlt
.size make_fcontext,.-make_fcontext
/* Mark that we don't need executable stack. */
.section .note.GNU-stack,"",%progbits
|
|
|
|
|
You will need to use the information from the stack trace to figure out which line caused the SEGV, and which value has not been set.
|
|
|
|
|
A quick glance brings up a problem here:
Stack::Stack() {
auto *local_stack= m_memPool.Allocate();
}
Perhaps I misunderstand the intention, but shouldn't this be:
Stack::Stack()
: local_stack(m_memPool.Allocate())
{}
|
|
|
|
|
Good catch; I missed that completely.
|
|
|
|
|
|
Can anybody help me? I want to launch a word processor(MS Word) in an MS Visual C++ dialog based application. How this can be done exactly. Thanks in advance for your help.
|
|
|
|
|
Would you like to embed MS Word into your dialog or just spawn the MS Word application from your dialog?
|
|
|
|
|
open MS Word from the dialog
|
|
|
|
|
Then use ShellExecute(Ex).
|
|
|
|
|
|
Don't have much idea about it...
|
|
|
|
|
Have you considered ShellExecute() ?
"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
|
|
|
|
|
Trying now...
Thanks for your help
|
|
|
|
|
I want to print a bitmap. To avoid printing small bitmap I set CScrollView mode as MM_LOMETRIC with sizes 3830x1995. I have created the bitmap and made the bitblt to the screen. There were everythig just like I want on the screen and on the print preview but when I printed the document I`ve got very bad result.
It seems to me that printer does not see a bitmap the same way as print preview does. Pay attantion that the first ractangle puts directly on the DC and memDC puts into it. Are there any ideas how to fix this mismatch between print previw and the real printing?
MFC_T_Print_1.zip[^]
void OnDraw()
{
CPen pen;
pen.CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
CPen* OldPen = pDC->SelectObject(&pen);
CRect rcView;
GetClientRect(rcView);
int iClientWidth = rcView.right;
int iClientHeight = rcView.bottom;
int iMemWidth = 1900;
int iMemHeight = 950;
CDC memDC;
CBitmap memBitmap;
memDC.CreateCompatibleDC(pDC);
memBitmap.CreateCompatibleBitmap(pDC, iMemWidth, iMemHeight);
memDC.SelectObject(&memBitmap);
memDC.SetMapMode(MM_LOMETRIC);
CPen pen1;
pen1.CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
memDC.SelectObject(&pen1);
CBrush brBK;
brBK.CreateSolidBrush(RGB(255, 255, 255));
memDC.SelectObject(&brBK);
RECT rc;
rc.left = 0;
rc.top = 0;
rc.right = iMemWidth;
rc.bottom = iMemHeight;
memDC.FillRect(&rc, &brBK);
memDC.Rectangle(rc.left, rc.top, rc.right, -rc.bottom);
memDC.MoveTo(0, 0);
memDC.LineTo(1900, -950);
memDC.MoveTo(0, -950);
memDC.LineTo(200, -750);
CFont font;
font.CreateFont(
50, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Arial"));
memDC.SelectObject(&font);
memDC.TextOut(100, -100, _T("Hello"));
pDC->BitBlt(10, -10, iMemWidth, -iMemHeight, &memDC, 0, 0, SRCCOPY);
font.DeleteObject();
brBK.DeleteObject();
memDC.DeleteDC();
memBitmap.DeleteObject();
pen.DeleteObject();
pen1.DeleteObject();
}
void OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
sizeTotal.cx = 3830;
sizeTotal.cy = 1995;
SetScrollSizes(MM_LOMETRIC, sizeTotal);
}
MFC
|
|
|
|
|
You need to set the mapping mode in the actual device context where you are writing the data. In this case you need to set it into the PrinterDC to make it consistent with the screen settings, and the actual image. See Mapping Modes and Translations | Microsoft Docs[^].
|
|
|
|
|
Mapping mode (MM_LOMETRICETRIC) has been set both in OnPrepareDC() and in OnPrint(). The result is the same - we still have mismatch between print preview and the real printing.
|
|
|
|
|