Help, cannot how to run unsafe - c#-4.0

How to run csc /unsafe *.cs
using System;
class UnsafeCode
{
unsafe static void Main()
{
int count = 99;
int* p;
p = &count;
Console.WriteLine("Initial value of count is " + *p);
*p = 10;
Console.WriteLine("New value of count is " + *p);
}
}
Error 1 Unsafe code may only appear if compiling with /unsafe C:\Documents and Settings\Eddy Ho\My Documents\Visual Studio 2010\Projects\608-UnsafeCode-Errors\608-UnsafeCode-Errors\Program.cs 5 26 608-UnsafeCode

It's a command line argument.
You use the Visual Studio command prompt and simply type it out.
You can also set this in the IDE, by going to the properties of the project, and in the Build tab select Allow unsafe code checkbox. See here.

Related

How do I disable MSVC warnings from headers included with quotes instead of angle brackets when using /analyze?

I am trying to add the /analyze flag to cl.
I am getting a warnings from external headers I #include "...", even though I am using /analyze:external- and /external:I ....
What am I doing wrong?
Example project:
main.cpp
#include "external.h"
// #include <external.h> <- hides external's warnings
int main() {
int shadowed = 0;
{ float shadowed = 0; }
return 0;
}
external.h
void something() {
int external_shadowed = 0;
{ float external_shadowed = 0; }
}
I run this command from the VS developer prompt:
cl /EHsc /analyze /analyze:external- /I include /external:I external /external:W0 main.cpp
And I proceed to get warnings from both files.
It seems MSVC only considers /external:I directories to actually be external if they are included with <> instead of "". This is not documented anywhere, and I would consider it a bug with the compiler. Third-party libraries should not necessarily always be included with <>.
More info and possibly updates in the future here: https://developercommunity.visualstudio.com/t/analyze:external--and-external:I-flags/1688240
I have not tested myself, but according to Hwi-sung Im [MSFT], <> and "" now act the same w.r.t /external:I in Visual Studio 2022 17.0.

size_t different default value when running through VS2013 debugger vs CommandLine

Running the following code via the visual studio debugger executes successfully. The "count" variable will be default initialized to 0.
If I run via the command line, i get random behaviour and my EXPECT_EQ( ... ) fails.
size_t expectedCount = actual.length() - expected.length();
position += 12;
size_t count;
for (size_t i = position ; i < actual.length(); ++i) {
if (actual.at(i) == 'a')
++count;
}
EXPECT_EQ(expectedCount , count);
I'm assuming this is because Visual studio gives me a clean stack (everything is 0) whereas the commandline has lingering garbage?
In a function scope, the syntax size_t count; will not initialize a variable. Use size_t count{};
For more info on initialization, see
Variable initialization in C++.
Your Debug build may be setting count to 0 due to the nature of that build configuration but not in Release build. You need to initialize count to zero. Always initialize variables.

Visual Studio warning C4334 on assignment but not on initialization

Why i got warning on this code:
#include <cstdint>
int main()
{
int i = 1;
int64_t i64;
i64 = 1 << i;
}
warning C4334: '<<' : result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)
but not on this:
#include <cstdint>
int main()
{
int i = 1;
int64_t i64 = 1 << i;
}
?
Tested on vs2013/2015.
I see the same discrepancy with vs2012. I don't think that there is a good reason for it - hopefully the warning will be emitted in both cases in a newer version of Visual C++.
MSVS 2015 Upd.2: Second case (on initialization) will trigger C4334 warning.

vim takes long time to scan tags when complete

my vim will scanning tags for a long time when press tab to complete.
I don't know it is about plugins or vimrc file.
it really annoy.
my vimrc is:https://gist.github.com/anonymous/5591546
it seems when I press tab it even scan the /usr/include directory,it take long time,it makes me crazy.
such when I edit a file like:
#include<stdio.h>
#include<ioste>
main()
{
int x = 8;
float y = 9.0;
char z = 'a';
int *p = &x;
float *q = &y;
char *r = &z;
printf("the *p address is %x\n",p);
printf("%d\n", sizeof(p));
printf("%d\n", sizeof(x));
printf("%d\n", sizeof(y));
printf("%d\n", sizeof(z));
printf("%d\n", sizeof(r));
printf("%d\n", sizeof(q));
printf("%c\n", *r);
printf("%f\n", *q);
}
in include
it will begin to tell scanning tags,and vim stuck.
The directories that are scanned for tags databases are configured by the 'tags' option. You seem to have /usr/include/** in there.
The insert mode completion uses the sources configured by the 'complete' option; by default, this includes tags via the t value. You can turn that off with :set complete-=t.
Note that you can also abort the lengthy scanning by pressing <C-c>.

neocomplecache&clang complete installed: code complete work for cpp file, whereas doesn't for c file

I have installed the vim plugin neocomplecache and clang complete and the patch of them named neocomplecache_clang_complete.
Also, I installed the clang to make clang complete works.
A pure c file named: test.c
typedef struct student
{
int age;
char name[20];
}Stu;
int main()
{
Stu Kevin;
Kevin.
}
After pressing the dot after "kevin" then "User defined completion (^U^N^P) Pattern not found" pops up.
A pure c file named: test.cpp
class Stu
{
int age;
char name[20]
};
int main()
{
Stu Kevin;
Kevin.
}
The members age and name pops up correctly.
I have checked the set omnifunc. It is the same value on two above scenarios
Is anyone able to find out what's going on here?
Feel free to let me know if you need more info, such as my .vimrc

Resources