打印

labVIEW和C语言的区别

[复制链接]
3206|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
gz688|  楼主 | 2011-6-29 15:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 gz688 于 2011-6-29 15:29 编辑

目前大多数PAC编程都是通过C语言来实现的,我摘取了面向对象的流行C++和 LabVIEW两种编程语言实例来进行比较:

[pre]/* Richard Wolf, 2002

99 bottles of beer on the wall in an extreme template-metaprogramming style.  
It uses template specialisation to decided how to print numbers, whether
'bottles' should be plural, and to finish the song correctly.  
Macros are used to generate the large number of specialisations required for
printing numbers nicely, eg 45 printed as "forty five" with pretty_print<45>().

Note that this will probably no compile immediately, since it requires the
compiler to instantiate templates to a depth of (number of bottles + 4).  
Either reduce the number of starting bottles, or increase the maximum
template depth on your compiler.

Eg. using g++ use the -ftemplate-depth-103 command line option.

Tested on gcc, other compilers at your risk
*/

#include <iostream>

using namespace std;

template<bool small, int I>
struct pretty_printer;

#define SMALL_PRETTY_PRINTER(num, string) \
template<>\
struct pretty_printer<true, num>\
{\
    static void print()\
    {\
        cout << string;\
    }\
};

SMALL_PRETTY_PRINTER(0, "No")
SMALL_PRETTY_PRINTER(1, "One")
SMALL_PRETTY_PRINTER(2, "Two")
SMALL_PRETTY_PRINTER(3, "Three")
SMALL_PRETTY_PRINTER(4, "Four")
SMALL_PRETTY_PRINTER(5, "Five")
SMALL_PRETTY_PRINTER(6, "Six")
SMALL_PRETTY_PRINTER(7, "Seven")
SMALL_PRETTY_PRINTER(8, "Eight")
SMALL_PRETTY_PRINTER(9, "Nine")
SMALL_PRETTY_PRINTER(10, "Ten")
SMALL_PRETTY_PRINTER(11, "Eleven")
SMALL_PRETTY_PRINTER(12, "Twelve")
SMALL_PRETTY_PRINTER(13, "Thirteen")
SMALL_PRETTY_PRINTER(14, "Fourteen")
SMALL_PRETTY_PRINTER(15, "Fifteen")
SMALL_PRETTY_PRINTER(16, "Sixteen")
SMALL_PRETTY_PRINTER(17, "Seventeen")
SMALL_PRETTY_PRINTER(18, "Eighteen")
SMALL_PRETTY_PRINTER(19, "Nineteen")

#undef SMALL_PRETTY_PRINTER

template<int ones>
inline void
print_ones();

#define ONES_PRINTER(ones, string) \
template<> \
inline void \
print_ones<ones>() \
{\
  cout << string;\
}

ONES_PRINTER(0, " ")
ONES_PRINTER(1, " one")
ONES_PRINTER(2, " two")
ONES_PRINTER(3, " three")
ONES_PRINTER(4, " four")
ONES_PRINTER(5, " five")
ONES_PRINTER(6, " six")
ONES_PRINTER(7, " seven")
ONES_PRINTER(8, " eight")
ONES_PRINTER(9, " nine")

#undef ONES_PRINTER

template<int tens>
inline void
print_tens();

#define TENS_PRINTER(tens, string) \
template<> \
inline void \
print_tens<tens>() \
{\
  cout << string;\
}

TENS_PRINTER(2, "Twenty")
TENS_PRINTER(3, "Thirty")
TENS_PRINTER(4, "Forty")
TENS_PRINTER(5, "Fifty")
TENS_PRINTER(6, "Sixty")
TENS_PRINTER(7, "Seventy")
TENS_PRINTER(8, "Eighty")
TENS_PRINTER(9, "Ninety")

#undef TENS_PRINTER

template<int I>
struct pretty_printer<false, I>
{
    static void print(){
        print_tens<(I - I%10)/10>();
        print_ones<(I%10)>();
    }
};

template<int I>
void pretty_print()
{
    pretty_printer<(I<20), I>::print();
}

template<int I>
inline void
BottlesOfBeer()
{
    pretty_print<I>();
    cout << " bottles of beer" ;
}

template<>
inline void
BottlesOfBeer<1>()
{
    pretty_print<1>();
    cout << " bottle of beer" ;
}

template<int I>
inline void
BottlesOfBeerOnTheWall()
{
    BottlesOfBeer<I>();
    cout << " on the wall";
}

template<int I>
inline void stanza()
{
    BottlesOfBeerOnTheWall<I>();
    cout << ",\n";
    BottlesOfBeer<I>();
    cout <<",\n";
}

template<int I>
inline void bridge()
{
    cout   << "Take one down, pass it around," << endl;
    BottlesOfBeerOnTheWall<I-1>();
    cout <<",\n";
}

template<>
inline void bridge<0>()
{
    cout << "Go to the store and buy some more," << endl;
    BottlesOfBeerOnTheWall<99>();
}

template<int I>
inline void verse()
{
    stanza<I>();
    bridge<I>();
}

template<int I>
inline void sing ()
{
    verse<I>();
    cout << endl;
    sing<I-1>();
}


template<>
inline void sing<0> ()
{
    verse<0>();   
}

int main () {
  sing<99>();
}


LabVIEW程序框图




labVIEW现在已经可以应用与ARM领域了,现在应用已经很广泛了,可以自己下载在桌面进行仿真调试咯
NI官方网站:
www.ni.com/arm
课件:
http://zone.ni.com/devzone/cda/tut/p/id/9214
LabVIEW For ARM软件评估板下载:
http://joule.ni.com/nidu/cds/view/p/id/1371/lang/en
客服论坛:
http://bbs.scadao.com/

相关帖子

沙发
风往南吹| | 2011-6-29 17:20 | 只看该作者
:(

使用特权

评论回复
板凳
740275789| | 2011-7-20 21:51 | 只看该作者
广告贴?虽然我也在做labview。。。。

使用特权

评论回复
地板
xiaotann| | 2011-7-22 11:48 | 只看该作者
编程的

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

0

主题

1

帖子

1

粉丝