小编nzo*_*xia的帖子

在给定FILE指针的情况下,如何找到文件名?

可能重复:
从C中的文件描述符
获取文件名从C中的文件指针获取文件名

我在这里有一个功能:

handle_file(FILE *file)
{
    if(condition)
    {
        print filename and other msg;
    }
}
Run Code Online (Sandbox Code Playgroud)

我们在这里唯一知道的是指向文件的指针; 是否可以根据指针获取文件名?

c file

16
推荐指数
1
解决办法
3万
查看次数

extern char**environ的定义在哪里?

我们可以在C中获取环境变量,如下所示:

extern char **environ;
int main(int argc, char *argv[])
{
    int count = 0;

    printf("\n");
    while(environ[count] != NULL)
   {
         printf("[%s] :: ", environ[count]);
         count++;
   }

   return 0;
}
Run Code Online (Sandbox Code Playgroud)

但环境的定义在哪里?我在unistd.h中找不到.它是如何工作的?

c linux

9
推荐指数
1
解决办法
1万
查看次数

在eclipse中更改调试视图的内容

我正在编写一个java框架,对于一个类文件sample.class,它会生成一个代理文件sample_proxy.class.当调用sample.testMethod()时,它会占用sample_proxy.class.我已经制作了一个eclipse插件来使断点工作, 在此输入图像描述

如果我从Main.java开始,并在sample.testMethod()中创建一个断点,下面的堆栈看起来像:Main.main - > sample.proxy_method - > sample_proxy.testMethod.
有没有办法让代理显示如下:Main.main - > sample.testMethod?

java eclipse eclipse-jdt

8
推荐指数
1
解决办法
320
查看次数

如何检查 configure.ac 中的特定 gcc 功能

例如,gcc 4.7 有一个新特性-Wnarrowing。在 configure.ac 中,如何测试当前 gcc 是否支持某个功能?gnulibc 中
有一个文件,但对我来说没有多大意义。

c c++ autoconf gcc

6
推荐指数
1
解决办法
2180
查看次数

container_of宏的定义

而不是将container_of定义为:

#define container_of(ptr, type, member) ({ \
            const typeof( ((type *)0)->member ) *__mptr = (ptr);
            (type *)( (char *)__mptr - offsetof(type,member) );})
Run Code Online (Sandbox Code Playgroud)

为什么这不会简单地工作:

#define container_of(ptr, type, member) ({ \
                    (type *)( (char *)(ptr) - offsetof(type,member) );})
Run Code Online (Sandbox Code Playgroud)

定义中第一行的用法是什么?

macros linux-kernel c-preprocessor

5
推荐指数
1
解决办法
423
查看次数

C++代码在g ++和vs2008中得到不同的结果

#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Exmpl{
    Exmpl()
    {
        cout << "Exmpl()" << endl;
    }

    Exmpl(const Exmpl&)
    {
        cout << "Exmpl(const Exmpl&)" << endl;
    }

    Exmpl& operator=(const Exmpl& rhs)
    {
        cout << "operator=Exmpl()" << endl;
        return *this;
    }

    ~Exmpl()
   {
        cout << "~Exmpl()" << endl;
   }
};

void func1(Exmpl obj)
{
}

void func2(Exmpl &obj)
{
}

Exmpl func3()
{
    Exmpl obj;
    return obj;
}

int main()
{
    Exmpl eobj;
    func1(eobj);
    func2(eobj);
    eobj = func3();
    Exmpl …
Run Code Online (Sandbox Code Playgroud)

c++

4
推荐指数
1
解决办法
246
查看次数

python top N字数,为什么多进程比单进程慢

我正在使用 python 进行频率字数统计,单进程版本:

#coding=utf-8
import string
import time
from collections import Counter
starttime = time.clock()
origin = open("document.txt", 'r').read().lower()
for_split = [',','\n','\t','\'','.','\"','!','?','-', '~']

#the words below will be ignoered when counting
ignored = ['the', 'and', 'i', 'to', 'of', 'a', 'in', 'was', 'that', 'had',
       'he', 'you', 'his','my', 'it', 'as', 'with', 'her', 'for', 'on']
i=0
for ch in for_split:
    origin = string.replace(origin, ch, ' ')
words = string.split(origin)
result = Counter(words).most_common(40)
for word, frequency in result:
    if not word in ignored and …
Run Code Online (Sandbox Code Playgroud)

python multiprocessing

4
推荐指数
1
解决办法
1439
查看次数

什么是"不可变变量"在函数式编程中意味着什么

我是函数式编程的新手,我真的无法理解"不可变"的概念.
例如,在SML中:

val a = 3
val a = a+1
Run Code Online (Sandbox Code Playgroud)

根据SML的原则,最后一行不会"改变"变量a的值,但现在等于4,有人可以为我解释一下吗?什么是"无突变"的好处?

functional-programming immutability

3
推荐指数
1
解决办法
4770
查看次数

c ++字符串类是只读的吗?

std::string test("this is a test string");
test[0] = 'b';
Run Code Online (Sandbox Code Playgroud)

像上面的代码一样,字符串的一部分已被更改,编译器是否会生成新字符串或对旧字符串进行修改?

c++ string

3
推荐指数
1
解决办法
934
查看次数

如何在tomcat中执行war包中的一些初始化代码?

我正在使用一个框架来处理一些请求,现在,我可以从这样的主函数启动它:

public Main{
        public static void main(String[] args) {
            
            //init the framework
            Init initer = new Init();
            initer.initFramework();
            
            //start my besiness code below
        }
    }
Run Code Online (Sandbox Code Playgroud)

现在我需要将我的项目打包成war格式并将其放入tomcat中,我怎样才能执行初始化代码?

java tomcat war

2
推荐指数
1
解决办法
811
查看次数