小编Wil*_*agh的帖子

静态const char*和const char之间的区别*

有人可以解释下面如何处理2个代码片段的区别吗?它们肯定会编译成不同的汇编代码,但我试图理解代码的行为方式可能不同.我知道字符串文字被抛入只读内存并且实际上是静态的,但是它与下面的显式静态有何不同?

struct Obj1
{
    void Foo()
    {
        const char* str( "hello" );
    }
};
Run Code Online (Sandbox Code Playgroud)

struct Obj2
{
    void Foo()
    {
        static const char* str( "hello" );
    }
};
Run Code Online (Sandbox Code Playgroud)

c++ string static char

15
推荐指数
3
解决办法
2万
查看次数

为什么这个makefile在'make clean'上执行目标

这是我目前的makefile.

CXX      = g++
CXXFLAGS = -Wall -O3
LDFLAGS  =

TARGET = testcpp
SRCS   = main.cpp object.cpp foo.cpp
OBJS   = $(SRCS:.cpp=.o)
DEPS   = $(SRCS:.cpp=.d)


.PHONY: clean all

all: $(TARGET)

$(TARGET): $(OBJS)
    $(CXX) $(CXXFLAGS) $(LDFLAGS) $(OBJS) -o $(TARGET)

.cpp.o:
    $(CXX) $(CXXFLAGS) -c $< -o $@

%.d: %.cpp
    $(CXX) -M $(CXXFLAGS) $< > $@

clean:
    rm -f $(OBJS) $(DEPS) $(TARGET)

-include $(DEPS)
Run Code Online (Sandbox Code Playgroud)

它有一个例外,完美地工作.如果目录已经是干净的(没有*.d,*.o)并且我运行'make clean',它会重新创建依赖项,然后立即删除它们:

[user@server proj]$ make
g++ -M -Wall -O3 foo.cpp > foo.d
g++ -M -Wall -O3 object.cpp > object.d
g++ …
Run Code Online (Sandbox Code Playgroud)

c c++ dependencies makefile gnu-make

15
推荐指数
2
解决办法
3597
查看次数

标签 统计

c++ ×2

c ×1

char ×1

dependencies ×1

gnu-make ×1

makefile ×1

static ×1

string ×1