今天我不得不使用这个basename()功能,而man 3 basename(这里)给了我一些奇怪的信息:
笔记
有两个不同版本的basename() - 上面描述的POSIX版本,以及GNU版本,后者可以使用
#define _GNU_SOURCE
#include <string.h>
我想知道这#define _GNU_SOURCE意味着什么:它是否污染了我用GNU相关许可证编写的代码?或者它只是用于告诉编译器类似" 嗯,我知道,这组函数不是POSIX,因此不可移植,但我还是想用它 ".
如果是这样,为什么不给人们不同的标题,而不是必须定义一些模糊的宏来获得一个函数实现或另一个?
有些东西也让我感到困惑:编译器如何知道哪个函数实现与可执行文件链接?它也使用这个#define吗?
有人有一些指示可以给我吗?
我在多个地方读到管道的默认缓冲区大小是4kB(例如,这里),我ulimit -a倾向于确认该语句:
$ ulimit -a
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 15923
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8 // 8 * 512B = 4kB
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, …Run Code Online (Sandbox Code Playgroud) 在编写一个简单的函数来从字符串中删除特定字符时,我遇到了这个奇怪的问题:
void str_remove_chars( char *str, char to_remove)
{
if(str && to_remove)
{
char *ptr = str;
char *cur = str;
while(*ptr != '\0')
{
if(*ptr != to_remove)
{
if(ptr != cur)
{
cur[0] = ptr[0];
}
cur++;
}
ptr++;
}
cur[0] = '\0';
}
}
int main()
{
setbuf(stdout, NULL);
{
char test[] = "string test"; // stack allocation?
printf("Test: %s\n", test);
str_remove_chars(test, ' '); // works
printf("After: %s\n",test);
}
{
char *test = "string test"; // non-writable?
printf("Test: %s\n", …Run Code Online (Sandbox Code Playgroud) 我正在尝试将我的项目移动到CMake,同时在编译过程中进行一些优化.
这是交易:
它看起来像这样:
.
libBig.a # made from object from subdir1 and subdir2
subdir1/
src/
libSubdir1.a
subdir2/
src/
libSubdir2.a
Run Code Online (Sandbox Code Playgroud)
今天,我设法使用一个全局变量,其中每个子目录CMakeLists.txt将附加自己的源文件.我在我的大库中使用此变量作为"源"输入:
# the big library depends on all the source files
# ${all_src} is automatically filled with each subdir's cpp file
get_property( BigLib_src GLOBAL PROPERTY all_src)
add_library( Big STATIC ${BigLib_src}) # recompiles all the sources
Run Code Online (Sandbox Code Playgroud)
现在,这可行,但不是太糟糕,但问题是,我的所有源文件都被编译两次:一次用于子库,一次用于大型库.
CMake似乎忘记了它已经构建了它们.
我必须保留subdir库,ar不能合并两个静态库.
你知道怎么做吗?
我想以人性化的方式在C#中打印我的小数字,例如:
30µfor 3E-5或456.789nfor 0.000000456789.
我知道C中的BSD 的Humanize_number()函数,但只与bit int兼容,而不是浮点数和双精度数.在C#中有相同的支持吗?
此外,它在显示数字时应保持一定的精度,例如:
0.003596应显示为3.596µ,而不是3.6µ(或更糟4µ).
这里可能的答案是:使用.NET格式化大数字但适用于负数log10会将数字截断为逗号后的1位数.在我看来,这还远未完成.
我想如何呈现东西的例子:
3000 3K
3300 3.3K
3333 3.333K
30000 30k
300000 300k
3000000 3M
3000003 3.000003M // or 3M if I specify "4 digits precision"
0.253 253m
0.0253 25.3m
0.00253 2.53m
-0.253003 -253.003m
Run Code Online (Sandbox Code Playgroud)
我无法在SO中提出我的问题以找到相关的答案,所以如果问题已经得到解答,请开火!
我的批处理文件有问题.它通过这样的方式自动构建几个程序:
所以它看起来像这样:
set FLAG=1
...
gmake all
call :interactive_check
set OTHERFLAG=1
...
gmake all
call :interactive_check
Run Code Online (Sandbox Code Playgroud)
其中有6或7个(它可能会增长).所以我创建了一个函数来检查errorlevel而不是在每一步复制/粘贴它.问题是:错误检查是通过一个函数完成的:
:interactive_check
if errorlevel 1 (
echo.
echo /!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\
echo Error in compilation process... exiting
echo /!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\/!\
echo.
cd %root_dir%
exit /B 1
) ELSE (
echo.Continuing to next step
)
goto:eof
Run Code Online (Sandbox Code Playgroud)
现在,在运行它时,exit /B 1只需退出函数,但不退出批处理文件.
你是否知道如何退出整个批处理文件而不必在每一步复制/粘贴我的"if errorlevel 1 .."?
我正在研究一种速度至关重要的嵌入式DSP,而且内存很短.
目前,sprintf使用我代码中任何函数的大部分资源.我只用它来格式化一些简单的文本:%d, %e, %f, %s没有精确或奇异的操作.
如何实现更适合我的使用的基本sprintf或printf函数?
我有一些奇怪的感觉abour sqlite3 参数,我想透露给你.
这是我的查询和失败消息:
#query
'SELECT id FROM ? WHERE key = ? AND (userid = '0' OR userid = ?) ORDER BY userid DESC LIMIT 1;'
#error message, fails when calling sqlite3_prepare()
error: 'near "?": syntax error'
Run Code Online (Sandbox Code Playgroud)
在我的代码中它看起来像:
// Query is a helper class, at creation it does an sqlite3_preprare()
Query q("SELECT id FROM ? WHERE key = ? AND (userid = 0 OR userid = ?) ORDER BY userid DESC LIMIT 1;");
// bind arguments
q.bindString(1, _db_name.c_str() …Run Code Online (Sandbox Code Playgroud) 我非常感兴趣地观看了Mojang"Mojam"for Humble Bundle(链接可能在很长一段时间内无效),在整个视频中,我看到了一些关于这些人如何使用他们的代码的好东西.
其中一个原因是其中一个开发人员在他的代码中使用ascii艺术评论来更好地浏览.
这给出了这样的东西:
/////////////////////////////////////////////
// ___ ___ ___ _ __ _ //
// / |/ | / | | | | \ | | //
// / /| /| | / /| | | | | \| | //
// / / |__/ | | / / | | | | | |\ | //
// / / | | / / | | | | | | \ | //
// /_/ |_| /_/ |_| …Run Code Online (Sandbox Code Playgroud) 我想点击一下这个应用程序中的链接:

当我点击"输出文件"链接时,我希望能够在我的应用程序中生成一个动作.
截至今天,链接在富文本QLabel中描述如下:
<a href="http://google.fr"><span style=" text-decoration: underline; color:#0000ff;">Output File"</span></a>
Run Code Online (Sandbox Code Playgroud)
(由Qt Designer生成)
点击后,它会打开默认的网络浏览器以转到Google.那不是我想要的; 我喜欢这样的东西:
<a href="#browse_output"><span style=" text-decoration: underline; color:#0000ff;">Output File"</span></a>
Run Code Online (Sandbox Code Playgroud)
并能够检测到点击的链接并做出相应的反应:
(pseudo code)
if( link_clicked.toString() == "#browse_output" ){
on_browse_output_clicked();
}
Run Code Online (Sandbox Code Playgroud)
Qt中是否可以使用QLabel(或接近某些东西)?怎么样?
c ×6
c++ ×3
arrays ×1
ascii ×1
batch-file ×1
buffer ×1
c# ×1
cmake ×1
embedded ×1
exit ×1
file ×1
function ×1
gnu ×1
humanize ×1
hyperlink ×1
linux ×1
numbers ×1
object ×1
parameters ×1
pipe ×1
pointers ×1
posix ×1
printf ×1
qlabel ×1
qt ×1
size ×1
sqlite ×1
stack ×1
static ×1
string ×1
sublimetext ×1
windows ×1