C 中 编程技巧

扫码查看
WEAK 范例

点击(此处)折叠或打开

  1. /* main.c */
  2. #include <string.h>
  3. #include <stdio.h>

  4. #define WEAK __attribute__ ((weak))
  5. //#define WEAK __weak

  6. int WEAK foo(int);

  7. #pragma weak foo = default_foo

  8. int main()
  9. {
  10.     int iret = foo(10);
  11.     printf("[%d]\n", iret);
  12. }

  13. int default_foo(int arg)
  14. {
  15.     return arg;
  16. }

点击(此处)折叠或打开

  1. #include <string.h>

  2. int foo(int a)
  3. {
  4.     return a*10;
  5. }

点击(此处)折叠或打开

  1. TARGET = foo
  2. SOURCE = main.c pub.c
  3. OBJS = $(SOURCE:.c=.o)

  4. .c.o:
  5.     gcc -o ${@} -c ${<}

  6. all: ${TARGET}

  7. ${TARGET}: ${OBJS}
  8.     gcc -o $@ ${OBJS}

其他还有

  1. #define PACK_END __attribute__((packed)) /*用于限定结构体单字节对齐*/

  2. typedef struct
  3. {
  4.     UINT8 channelNumber;
  5.     UINT64 startTime;
  6.     UINT16 duration;

  7. } PACK_END IEEEtypes_Common11hHdr_MeasReq_t;

  8. //另外有些编译要求的语法为
  9. typedef __packed struct
  10. {
  11.     UINT8 channelNumber;
  12.     UINT64 startTime;
  13.     UINT16 duration;

  14. } IEEEtypes_Basic_MeasReq_t

10-25 19:35
查看更多