C++ µ÷C Cµ÷c++
Ò»¡¢c++ µ÷C:
/* cÓïÑÔÍ·Îļþ£ºcExample.h */
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
#ifdef __cplusplus
extern "C"
{
#endif
int add(int x,int y);
#ifdef __cplusplus
}
#endif
#endif
/* cÓïÑÔʵÏÖÎļþ£ºcExample.c */
#include "cExample.h"
int add( int x, int y )
{
return x + y;
}
// main.cpp
#include <iostream>
using namespace std;
// c++ʵÏÖÎļþ£¬µ÷ÓÃadd()
#include "cExample.h"
int main(int argc, char* argv[])
{
cout << add(2,3) << endl;
return 0;
}
¶þ¡¢Cµ÷C++
//C++Í·Îļþ cppExample.h
#ifndef CPP_EXAMPLE_H
#define CPP_EXAMPLE_H
#ifdef __cplusplus
extern "C"
{
#endif
int add(int x,int y);
#ifdef __cplusplus
}
#endif
#endif
//C++ʵÏÖÎļþ cppExample.cpp
#include "cppExample.h"
int add( int x, int y )
{
return x + y;
}
/* CʵÏÖÎļþ */
#include <stdio.h>
#include "cppExample.h"
int main( int argc, char* argv[] )
{
printf ("%d\n", add( 2, 3 ));
return 0;
}
Ïà¹ØÎĵµ£º
ÄÚÈÝÕªÒª£º±¾ÎÄÏêϸϵͳµØ½éÉÜÁËuC/OS-IIÔÚ51µ¥Æ¬»úÉϵÄÒÆÖ²¡¢ÖØÈëʵÏÖ·½·¨¡¢Ó²¼þ·ÂÕæ¡¢¹Ì»¯¡¢ÈË»ú½çÃæµÈ¹Ø¼üÄÚÈÝ¡£
¹Ø¼ü´Ê£ºÇ¶Èëʽʵʱ¶àÈÎÎñ²Ù×÷ϵͳ¡¢uC/OS-II¡¢C51
ÒýÑÔ£º
Ëæ×Ÿ÷ÖÖÓ¦Óõç×ÓϵͳµÄ¸´ÔÓ»¯ºÍϵͳʵʱÐÔÐèÇóµÄÌá¸ß£¬²¢°éËæÓ¦ÓÃÈí¼þ³¯×Åϵͳ»¯·½Ïò·¢Õ¹µÄ¼ÓËÙ£¬ÔÚ16λ/32λµ¥Æ¬»úÖÐ¹ã·ºÊ¹Ó ......
ʱ³£ÔÚcppµÄ´úÂëÖ®Öп´µ½ÕâÑùµÄ´úÂë:
#ifdef __cplusplus
extern "C" {
#endif
//Ò»¶Î´úÂë
#ifdef __cplusplus
}
#endif
ÕâÑùµÄ´úÂëµ½µ×ÊÇʲôÒâË¼ÄØ£¿Ê×ÏÈ£¬__cplusplusÊÇcppÖеÄ×Ô¶¨Òåºê£¬ÄÇô¶¨ÒåÁËÕâ¸öºêµÄ»°±íʾÕâÊÇÒ»¶ÎcppµÄ´úÂ룬Ҳ¾ÍÊÇ˵£¬ÉÏÃæµÄ´úÂëµÄº ......
±¾ÎĽéÉÜÔÚGNU/Linux»·¾³ÏÂÒ»¸öC³ÌÐòÓÉÔ´´úÂëµ½³ÌÐò£¬µ½¼ÓÔØÔËÐУ¬×îºóÖÕÖ¹µÄ¹ý³Ì¡£Í¬Ê±ÒԴ˹ý³ÌÎªÔØÌ壬½éÉÜGNU/Linuxƽ̨ÏÂÈí¼þ¿ª·¢¹¤¾ßµÄʹÓá£
±¾ÎÄÒÔÎÒÃÇ×î³£¼ûµÄhello, world!ΪÀý£º
#include <stdio.h>
main ()
{
printf(“hello, world!\n” ......
ÏÂÃæÕâ¶Î´úÂëÓÐɶ´íÎó£¿
#if ULONG_MAX == 0xFFFFFFFF
inline unsigned long byte_swap(unsigned long x) { return __builtin_bswap32(x); }
inline long byte_swap(long x) { return __builtin_bswap32(x); }
#else
inline unsigned long byte_swap(unsigned long x) { return __builtin_bswap64(x); }
inline long ......
×î½üÔÚ×öÒ»¸öI2C¼üÅ̵ÄLinuxÇý¶¯£¬²Î¿¼ÁËÆäËûоƬµÄһЩ´úÂ룬ÆäÖÐÂ½Ðø·¢ÏÖÓÐЩÈÃÈËÃÔ»óµÄ¶«Î÷£¬°ÑÎÒµÄÃÔ»ó¼°Àí½âÔÚÕâÀï¼ÓÒԼǼ£º
1. i2c_driver½á¹¹ÌåµÄprobe³ÉÔ±µÄÔÐÍ£º
int (*probe)(struct i2c_client *, const struct i2c_device_id *);
¼´£ºprobeº¯Êý±»µ÷ÓÃʱ»á´ÓÉϱߴ«Á½¸ö¸ö²Î ......