Hello world and Warning C4530 [SOLVED]

Was doing the Hello world in Visual Studio Code 2019 and get this output of code after Hello.cpp
Capture
Anyone know why this is happening and can explain a way to fix?

3 Likes

Because that operator can throw an exception. You will need to add /EHsc when compiling e.g.

cl main.cpp /EHsc

Means use C++ exception handling and C code (through extern C) can’t throw exceptions.
http://www.cplusplus.com/doc/tutorial/exceptions/

2 Likes

Can you explain what you meant here in more detail? I think there might be a typo - the sentence doesn’t make sense.

No typo, C++ has an error handling mechanism called exceptions. That compiler switch is to use them. You don’t need to know more than that at this stage, even if you don’t understand.

But the door has been open and I want to know, don’t keep us ignorant that statement is like saying Hey! there’s a fire in the corner but ignore it for now. At the minimum please point us in the right direction to learn more information about this so the other users will understand when they come across this.

Did you look at the link provided? You’re asking how to run before you’ve learnt to crawl, it’s just not gonna make sense.

1 Like

Yes I saw the link provided, my apologies for jumping before I absorbed all information in your post. Though I have an associate’s degree in computer science I have not coded in years I’m familiar with the basic concepts and jargon of visual programming, I have crawled I have walked I took a nap. But thank you for your quick and fast replies I will absorb the information and figure this out.

Hey Dan, thank you for the feedback, but I think you misunderstood the question I was asking. Hopefully I can clarify now that I’ve had a chance to do some more research. I’m familiar with C++ exception handling and have used it extensively (especially with COM programming), however I was less clear on the details of the /EHsc switch. The link you provided explains exceptions, but says nothing about the switch in question. This link explains the switch in more detail: https://docs.microsoft.com/en-us/cpp/build/reference/eh-exception-handling-model?view=vs-2019

I originally thought there might have been a typo in the sentence I quoted because without more detailed information on the switch, the sentence itself didn’t make sense to me. I had to re-read it a couple times because at first couple glances it seemed like there were pieces missing. Now that I have context, I understand what you were trying to say.

As to why I wasn’t as familiar with the switch, well, I had a feeling that I had seen it somewhere before, and it turns out my hunch was correct - it’s already included by default with new C++ projects created with VS. But with VSC, we have to do things manually. This is actually a good thing, because we’ll learn things along the way (like the purpose of this command line switch) that would otherwise be set up for us automatically. There are in fact several command line switches for both compiler and linker that I assume we’ll visit as the lessons progress.

Hope that clears things up!

3 Likes

Definitely misunderstood, wasn’t clear to me you were asking about the specifics of the switch itself.

Visual Studio projects also have a few others enabled by default. Ones that I can remember off the top of my head

/Zi //debug info
/W3 //level 3 warnings
/permissive- //standards conformance

Thanks @SteveMerritt Your post was the information I was looking for great work. So if we did this same code in VS the warning would not appear because it would have been included, but not so in VSC the reason the code warning appears but the code still works.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms