Thursday, September 20, 2012

Refer to .net assemblies from vc9/.net 3.5 apps

Our partner gave us some components built with .net 4.0, and our hosting application is mixed application based on 3.5, when trying to refer to them, the compiler complains with errors. Finally figure out how to make it work.

After inserting the reference, unload the project, manually adding the

   1: <ProjectReference Include="XXXX.csproj">
   2:       <Project>{2897acf2-f168-4c4b-8a4e-b1dedd8733fc}</Project>
   3:       <SpecificVersion>true</SpecificVersion>
   4: </ProjectReference>

<SpecificVersion> node also applies to the assembly reference.


Then force the app to load .net 4.0 during the runtime:


 



   1: <startup useLegacyV2RuntimeActivationPolicy="true">
   2:     <supportedRuntime version="v4.0"/>
   3: </startup>

If using visual studio 2010 to build vc9/3.5 c++ apps, change the target to vc9,


then manually change the target framework to 3.5:



   1: <PropertyGroup Label="Globals">
   2:     <ProjectGuid>{0D090EBF-7467-4DA5-8AE4-E6A52335F0AA}</ProjectGuid>
   3:     <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
   4:     <Keyword>ManagedCProj</Keyword>
   5:     <RootNamespace>xxxx</RootNamespace>
   6: </PropertyGroup>

Tuesday, September 11, 2012

Trigraph in C literal string

Last week, one of my colleague asked me one question, the c++ codes like:

char *p = "??--AB";

will be translated to “~-AB” automatically by the compiler.

After checking the standard reference document, found

image

Really an interesting point for old C codesSmile

The wiki says:

History

The basic character set of the C programming language is a subset of the ASCII character set that includes nine characters which lie outside the ISO 646 invariant character set. This can pose a problem for writing source code when the keyboard being used does not support any of these nine characters. The ANSI C committee invented trigraphs as a way of entering source code using keyboards that support any version of the ISO 646 character set.

[edit]Implementations

Trigraphs are not commonly encountered outside compiler test suites.[1] Some compilers support an option to turn recognition of trigraphs off, or disable trigraphs by default and require an option to turn them on. Some can issue warnings when they encounter trigraphs in source files. Borland supplied a separate program, the trigraph preprocessor, to be used only when trigraph processing is desired (the rationale was to maximise speed of compilation).