由买买提看人间百态

topics

全部话题 - 话题: endif
首页 上页 1 2 3 4 5 (共5页)
g*********s
发帖数: 1782
1
来自主题: Programming版 - which str_cmp code is better?
so this is good?
#ifndef _HAVE_STRING_ARCH_strcmp
# if __GNUC_PREREQ (3, 2)
# define strcmp(s1, s2) \
__extension__
\
({ size_t __s1_len, __s2_len;
\
(__builtin_constant_p (s1) && __builtin_constant_p (s2)
\
&& (__s1_len = strlen (s1), __s2_len = strlen (s2),
\
(!__string2_1bptr_p (s1) || __s1_len >= 4)
\
&& (!__string2_1bptr_p (s2) || __s2_len >= 4)) ... 阅读全帖
t****t
发帖数: 6806
2
不对
you need this construction
#ifndef XXXX
#define XXXX
// your .h file goes here
#endif
O*******d
发帖数: 20343
3
因为C/C++compiler不能保证同一个头文件不被包括一次以上,所以码工需要多写几
行#define. 这种基本上成了标准写法
#ifndef XXXXX // 最先一行
#define XXXXX
头文件的内容
#endif //最后一行
对XXXXX的要求只需要独特即可。当然要满足identifier的条件。
r****t
发帖数: 10904
4
非 template 情况似乎比较清楚了,class template 里面的 static data
member 的定义和初始化有没有啥龟腚?
举个例子:
template
class StackWithCapacity : public stack_adapter
{
public:
typedef typename stack_adapter< Container>::size_type size_type;
private:
static const size_type capacity = 5;
};
capacity 是个 static const member, 我就直接在 class body 里面初始化了,
据 c++ primer,class body 外面还必须 define without initializer (虽然我我不这么做也能编译并运行正常). 这样我就在外面加
template
StackWithCapacity... 阅读全帖
h**********c
发帖数: 4120
5
来自主题: Programming版 - C++ template preprocessor
Try to figure it out but failed,as the following:
void takefloat (float * ) {}
void takedouble (double *) {}
template
void dosomething (T * pt)
{
#if sizeof(T) == sizeof(float)
takefloat (pt);
#else
takedouble(pt);
#endif
}
Compilation failed.
A**u
发帖数: 2458
6
来自主题: Programming版 - C++ template preprocessor
我觉得,你这个不行的原因在
#if sizeof(T) == sizeof(float)
sizeof(T)要运行时才知道
你改成
#if XXX
#else
#endif
编译时候加上 g++ -DXXX 选择float, g++ 选择double
或者
你改成void take (float * ) {}
void take (double *) {}
template
void dosomething (T * pt)
{
take(pt);
}
这样可行吗
h**********c
发帖数: 4120
7
来自主题: Programming版 - C++ template preprocessor
Try to figure it out but failed,as the following:
void takefloat (float * ) {}
void takedouble (double *) {}
template
void dosomething (T * pt)
{
#if sizeof(T) == sizeof(float)
takefloat (pt);
#else
takedouble(pt);
#endif
}
Compilation failed.
A**u
发帖数: 2458
8
来自主题: Programming版 - C++ template preprocessor
我觉得,你这个不行的原因在
#if sizeof(T) == sizeof(float)
sizeof(T)要运行时才知道
你改成
#if XXX
#else
#endif
编译时候加上 g++ -DXXX 选择float, g++ 选择double
或者
你改成void take (float * ) {}
void take (double *) {}
template
void dosomething (T * pt)
{
take(pt);
}
这样可行吗
l******d
发帖数: 530
9
来自主题: Programming版 - 问个两个.h文件互相include的问题
a.h开头和结尾有#ifndef A_H和#endif的,原帖为了省事没敲进去,现在补上了
h**********c
发帖数: 4120
10
来自主题: Programming版 - forward declaration
As I understand, include "xxx.h" means copying all ines in "xxx.h" here.
So you need guard const.
#ifndef __xxx_h
#define __xxx_h
your stuff
#endif
y***d
发帖数: 2330
11
来自主题: Programming版 - 关于C++中 extern "C"的问题。
把 parser.c "放到我其他的C++程序中" 这个做法是不好的,应该是把 parser.h 包含
到其它 .c/.cpp 文件中,
而 parser() 的函数体可以在 .c 中,也可以在 .cpp 中,
1. in c
parser.h
#ifdef _cplusplus
extern "C"{
#endif
void parser();
...
and complie parser.c with gcc
2. in cpp
parser.h
void parser();
and compile parser.cpp with g++

libxml2,
f******n
发帖数: 640
12
来自主题: Programming版 - 弱问C++一个问题 一直不解
写了一段程序试了一下
声明try.h:
#ifndef TRY_H_INCLUDED
#define TRY_H_INCLUDED
int add_two_number(int& a, int& b);
#endif // TRY_H_INCLUDED
然后是定义try.cpp:
#include "try.h"
int add_two_number(int& a, int& b)
{
return a+b;
}
然后是主程序:
#include "try.h"
#include
using namespace std;
int main()
{
int x1=1;
int x2=2;
int x3=add_two_number(x1, x2);
cout< cout< }
可以一直不能运行啊
但是在主程序中只有加了#include "try.cpp"才可以运行
这是怎么回事呢?
谢谢了
h*******n
发帖数: 82
13
来自主题: Programming版 - 弱问C++一个问题 一直不解
.h加个extern改成
#ifndef TRY_H_INCLUDED
#define TRY_H_INCLUDED
extern int add_two_number(int& a, int& b);
#endif // TRY_H_INCLUDED
虽然是全局函数,但是默认只有自己的编译单元可见,加个extern才能在其他单元里面
使用
G*****7
发帖数: 1759
14
i think you are looking for preprocessor definitions.
in your source code:
#ifdef Load_FILE
cout << "Load_FILE is defined";
#else
cout << "Load_FILE is not defined";
#endif
in your compiler settings, add:
-DLoad_FILE
without space between -D and your preprocessor definition.
G*****7
发帖数: 1759
15
yes, because you can use enums (compile time consts) or tag classes in place
of preprocessor defs, and dispatch to os-specific code paths.
no, because your enums or tages will be most likely based on preprocessor #
if.
struct linux_tag {};
struct win32_tag {};
#ifdef LINUX
struct os_tag : linux_tag {};
#...
...
#endif
w*s
发帖数: 7227
16
can i do this,
class linux_app: base_class
{
}
class win_app: base_clase
{
}
main()
{
#ifdef LINUX
new linux_app();
#else defined WIN
new win_app();
#endif
}

place
h*****f
发帖数: 248
17
来自主题: Programming版 - Re: L 电面 (转载)
【 以下文字转载自 JobHunting 讨论区 】
发信人: henrysf (Henry), 信区: JobHunting
标 题: Re: L 电面
发信站: BBS 未名空间站 (Thu Oct 18 01:46:20 2012, 美东)
我写了以下的code, 之后就被拒了, 回信是说别的candidate写得比较好, 我还没看出
问题.
Additional requirements:
- The only operators you need to implement are +, -, *, and /.
However, your implementation should make it relatively easy to
add more operators.
- The calculator should accept floating point numbers and output
floating point numbers (i.e. when the input is 2 3 / the result
is 0.66667).
- ... 阅读全帖
d*********8
发帖数: 2192
18
来自主题: Programming版 - 今天被一个面试问题难住了
FYI
#ifndef CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field) \
((type *)((PCHAR)(address) - (ULONG_PTR)(&((type *)0)->field)))
#endif
d*********8
发帖数: 2192
19
来自主题: Programming版 - 今天被一个面试问题难住了
FYI
#ifndef CONTAINING_RECORD
#define CONTAINING_RECORD(address, type, field) \
((type *)((PCHAR)(address) - (ULONG_PTR)(&((type *)0)->field)))
#endif
c*******h
发帖数: 1096
20
来自主题: Programming版 - C和C++的复数
C和C++的复数好像不是很兼容。下面这个问题怎么办?
我有一个legacy.h,里面定义了一个dummy函数
#ifndef _LEGACY_
#define _LEGACY_
#include
void dummy(complex x);
#endif
用gcc是可以编译的
然后我写一个驱动器driver.c
#include
#include "legacy.h"
int main(void) {
complex c = 4.0;
dummy(c);
return 0;
}
gcc也是能编译的
然而我把driver.c改成driver.cpp,g++编译就不通过了,说
In file included from driver.cpp:2:0:
legacy.h:4:20: error: ISO C++ forbids declaration of 'x' with no type [-
fpermissive]
driver.cpp: In function 'int main()':
driver.cpp:4:11: e... 阅读全帖
t****t
发帖数: 6806
21
来自主题: Programming版 - C和C++的复数
先讲C. C里的complex在C99开始成为标准. 三个浮点类型有相对的三个浮点复数类型, 即
float _Complex, double _Complex, long double _Complex.
complex是一个宏, 展开成_Complex. 但是具体实现允许不定义这个宏, 或者undef它.
所以这个是不安全的.
C99允许写complex a;或者_Complex a;这样的写法.
C++98不兼容C的写法. C++11兼容double _Complex a;这样的写法(#include >), 但是complex被重新用于std::complex了, 所以没有complex==_Complex这一说.
C++不能使用_Complex a;这样的写法.
最后, 所有的实现在二进制表示上都是兼容的, 都等同于T [2]的结构, 不管是T
complex, T _Complex, 还是std::complex.
所以你可以做的是, 在.c里用double _Complex, 在.cpp里用std::complex.
.h就... 阅读全帖
m**********e
发帖数: 220
22
来自主题: Programming版 - 问低级问题
在virtual box里编写c程序,想写头文件的话
.h文件保存在哪里呢
gedit一个.h文件,写了然后保存了
但是其他程序来include的时候却说没有这个文件
是怎么回事呢
#ifndef __HARDWARE_H__
#define __HARDWARE_H__
//代码部分
#endif
为什么HARDWARE_H是大写的呢
而#include 用的时候确是小写
基础问题,多谢回答!
p*****2
发帖数: 21240
23
来自主题: Programming版 - 关于python

我还见过有人在C中
#ifdef test
test code
...
#endif
t****t
发帖数: 6806
24
你想问啥? vim的语法配对又不限括号, 包括#ifdef/#endif都可以配对的. 我说的begi
n/end是指pascal.
p****r
发帖数: 165
25
来自主题: Programming版 - excel/access VBA
is there a hotkey could be used to match long if /else/end if statement.
when if statement is upper long, and there are other if/endif statement
inside, soon lost track where it end.
Thanks.
b***i
发帖数: 3043
26
如何在多个文件中简单的定义一个全局变量呢?
这样:在main.h里面定义
#ifdef MAIN
#define extern
#endif
extern int timer_tick;
这样,main.c里面
#define MAIN
#include "main.h"
就定义了全局变量,而其他的文件用main.h就自动用了extern int timer_tick;而main
.c里面看到的没有extern.
k****e
发帖数: 126
27
可以這樣
main.h:
#ifdef MAIN
#define EXTERN_W
#else
#define EXTERN_W extern
#endif
EXTERN_W int timer_tick;
main.c:
#define MAIN
#include "main.h"
c******g
发帖数: 63
28
来自主题: Programming版 - C#中如何share Pre-processing directives
在C++中,如果我在一个头文件mine.h中#define MINE 0,那只要我以后在其他文件中#
include mine.h,MINE这个宏就被视作定义了。日后我comment掉mine.h中的#define
MINE 0这一句,其他文件中也会有相应的改变。
但是好像C#的pre-processing directives做不到这一点。。。因为放在一个工程里,
都不用显式地include一个文件,就可以用写在那个文件中的类。而且,貌似pre-
prepocessing directives只在本文件scope之内。如果我class1.cs和class2.cs都有
#ifdef MINE
....
#else
....
#endif
之类的条件编译。那我每次要换一种编译,都得同时到两个文件中comment或uncomment
掉#define MINE这一句。如果是N个文件呢?麻烦得要死。。。
各路高人,请指教一下有没有良策。多谢!
N********n
发帖数: 8363
29
来自主题: Programming版 - C#中如何share Pre-processing directives
Macro definition is a major no-no in modern programming language as
it could ruin intellisense and tooling support.
Imagine you have a macro like this:
#ifdef SOMETHING
#define SCREW_UP {
#else
#define SCREW_UP }
#endif
Now what is SCREW_UP when it's used in your code to an IDE, { or }?
When such macro shows up, IDE is all confused and thus cannot run
intellisense or refactoring properly. This is one major reason why
MARCO definition is dropped from modern PMs.
j******t
发帖数: 788
30
那就再套#define macro
#define P_a (struct A*)p_v
#define P_b (struct B*)p_v
#ifndef CAST_Pv
#define CAST_Pv(type) \
if...
P_a
or P_b
#endif
然后用CAST_Pv(type).
h*****n
发帖数: 209
31
来自主题: Programming版 - 怎么comment out大块包含/* */的code?
#if 0
/*
...
*/
#endif
d****i
发帖数: 4809
32
来自主题: Programming版 - C问题,被64bit iPhone搞晕了
所以比较好的方法是,针对不同的处理器,采用头文件types.h来自定义:
#ifdef _ARM_CORTEX
typedef int INT32;
typedef unsigned int UINT32;
typedef short INT16;
......
#endif
T********i
发帖数: 2416
33
来自主题: Programming版 - 建议大家看看interlocked
#if defined(_MSC_VER)
# pragma once
#include
inline long long InterlockedIncrement(long long volatile *ptr) {
return InterlockedIncrement64(ptr);
}
inline long long InterlockedDecrement(long long volatile *ptr) {
return InterlockedDecrement64(ptr);
}
#else
#include
template
inline T InterlockedIncrement(T volatile *ptr) {
return __sync_add_and_fetch(ptr, 1);
}
template
inline T InterlockedDecrement(T volatile *ptr) {
return __sync... 阅读全帖
T********i
发帖数: 2416
34
多谢thrust。我曾经自己做了个类似的。
我还做了个encoding的。
size_t Convert::encodeFloatValue(double value, char *buffer) {
char floatBuffer[FLOAT_BUFFER_LEN];
int dec, sign;
int result;
#if defined(_MSC_VER)
result = _ecvt_s(floatBuffer, FLOAT_BUFFER_LEN, value, 15, &dec, &
sign);
return ecvtBuffer2String(floatBuffer, buffer, dec, sign);
#else
char *ret = ecvt(value, 15, &dec, &sign);
return ecvtBuffer2String(ret, buffer, dec, sign);
#endif
}
ecvtBuffer2... 阅读全帖
z*y
发帖数: 1311
35
来自主题: Programming版 - 一个gcc 问题

yes, like below
#include
int main()
{
#ifdef CLS
printf("CLS=%d\n", CLS);
#endif
return 0;
}
g*********e
发帖数: 14401
36

#ifdef WIN
windows thread
#else
linux thread
#endif
不过pthread的api应该都可以通吃
d****i
发帖数: 4809
37
来自主题: Programming版 - 请教unit test的best practice
Re 这个,利用友元函数可以access私有成员函数的特点,在类里面加上
#ifdef _TEST
friend class MyUnitTest;
#endif
gw
发帖数: 2175
38
来自主题: Programming版 - self defined data type problem
这样定义了数据类型
#ifdef USE_DOUBLES
typedef double dataType;
#else
typedef float dataType;
#endif
然后在程序中如果出现
std::complex x,y;
x=complex(2.0,0);
y = 2.0*x
就会有这样的问题:
Type no match for 'operator/' (operand types are 'std::complex' and '
double')
如何破?
s********1
发帖数: 581
39
gcc 编译的时候要包括 header source file 吗?
main.c 的程序中引用了sub.h 和 sub.c 中定义的function pphh(),
***************************************************************
//File: main.c
#include
#include "sub.h"
void main()
{
pphh();
}
*************************************************
//File: sub.h
#ifndef _sub_h
#define _sub_h
void pphh();
#endif
************************************************
//File: sub.c
#include
#include "sub.h"
void pphh()
{
printf("pphh\n");
}
************************
s********1
发帖数: 581
40
gcc 编译的时候要包括 header source file 吗?
main.c 的程序中引用了sub.h 和 sub.c 中定义的function pphh(),
***************************************************************
//File: main.c
#include
#include "sub.h"
void main()
{
pphh();
}
*************************************************
//File: sub.h
#ifndef _sub_h
#define _sub_h
void pphh();
#endif
************************************************
//File: sub.c
#include
#include "sub.h"
void pphh()
{
printf("pphh\n");
}
************************
l********r
发帖数: 175
41
【 以下文字转载自 Linux 讨论区 】
发信人: lilyflower (smile), 信区: Linux
标 题: what kind of language this is and how to change it?
发信站: BBS 未名空间站 (Fri Aug 8 11:58:26 2008)
In my f90 source code files, it has following lines:
#ifdef SYNC
call mpi_barrier(mpi_comm_world,ierror)
#endif
what kind of languages that used? when using gfortran compiler to compile it
, I got warning message as: Illegal preprocessor directive.
I tried to correct it. How to change the source code or makefile a little
bit so that
c*****t
发帖数: 1879
42
来自主题: Unix版 - bsplit.c
/* a code I wrote long time ago for this purpose */
#include
#include
#include
#include
#include
#include
#ifndef true
#define true 1
#define false 0
#endif
int Error (char *);
long filelength (FILE *f)
{
register long size, pos = ftell (f);
fseek (f, 0, SEEK_END);
size = ftell (f);
fseek (f, pos, SEEK_SET);
return size;
}
int writefile (FILE *infile, char *filename, long filesize)
{
FILE *outfile;
char buffer[409
i*******n
发帖数: 166
43
来自主题: Unix版 - [转载] 再请教高手
run this script in your directory
#!/bin/tcsh -f
while(1)
if ( -e index.html) then
your_perl_script index.html
mv -f index.html `date +%d%m_%H%M`.html
else
sleep 60
endif
end
g*k
发帖数: 194
44
偶在编译程序时遇到了问题,
系统好象不明白执行条件编译的语句:
70: ifeq "$(SYSTEM_NAME)" ""
71: SYSTEM_NAME = Solaris
72: endif
在IRIX上系统报告说,“71:must be a seperator (: or ::) for
rules"
在solaris上系统说,"Fatal error in reader: makefile, line
71: Unexpected end of line seen"
这一部分只是定义一些 local variable,并没有真正去编译。
我的问题是gnu的make是否不能识别 ifeq 语句?
我查了在线帮助,好象没提条件编译的事。而gnu的make手册
说明这样的调用是正确的。请大虾赐教
c*****e
发帖数: 32
45
来自主题: Unix版 - [转载] 求救
这其实是选项 -D 作用是 Define macro macro with the string `1' as its
definition
一般人在程序里边加一些 debug 的 code block,用 "#ifdef DEBUG" 和 "#endif" 括起

当编译时想要包含DEBUG 的 code 就用编译选项 -DDEBUG
t*******l
发帖数: 421
46
要实现下列功能:进入目录bbs,显示所有subdir,从屏幕输入要考古的subdir,
进入该目录,浏览最后一片文章.大致是这样的.
cd bbs
ls
read -p " " answer if ( -e $argv[1]) then
cd $argv[1]
pico lastpost
else
echo2 file $argv[1] doesn't exist
endif
学这个都两星期了,还是创不出来可以执行的小程序来.
请大虾指导指导.
e******r
发帖数: 220
47
来自主题: Unix版 - a puzzle!!
what is the meaning of this little shell program? Please help me.
Especially, what is the function of "tcsh" command?
echo "begin $*"
if ("$1" != "")then
shift
tcsh script.sh $*
endif
echo "end"
fi
a****y
发帖数: 1035
48
来自主题: Unix版 - [转载] Shell高手看过来。
#!/bin/csh
foreach fn (*)
grep 'aaa' $fn >/dev/null
if ($status == 0) then
cp $fn /newdir
endif
end
c*****t
发帖数: 1879
49
来自主题: Unix版 - [转载] qestion about grep
easy, do something like:
if ( `grep ....` ) then
endif
ps, tcsh is not supposed to be used in shell programming. Use
standard shell instead.
s********1
发帖数: 581
50
gcc 编译的时候要包括 header source file 吗?
main.c 的程序中引用了sub.h 和 sub.c 中定义的function pphh(),
***************************************************************
//File: main.c
#include
#include "sub.h"
void main()
{
pphh();
}
*************************************************
//File: sub.h
#ifndef _sub_h
#define _sub_h
void pphh();
#endif
************************************************
//File: sub.c
#include
#include "sub.h"
void pphh()
{
printf("pphh\n");
}
************************
首页 上页 1 2 3 4 5 (共5页)