它甚至可以实现吗?
我们需要STDERR(即其他流然后STDOUT)具有不同的colo(u)r.例如红色.
我们使用bash,终端应该是Konsole(XTerm,gnome终端或任何可用的).
谢谢,如果你知道:-)
伙计们,我有这个问题:
通常在C99 GCC(cygwin/MinGW/linux)中,C struct中的初始化器有点符号语法.
像这样:
//HELP ME HOW TO REWRITE THIS (in most compact way) to MSVC
static struct my_member_t my_global_three[] = {
{.type = NULL, .name = "one"},
{.type = NULL, .name = "two"},
{.type = NULL, .name = "three"},
};
Run Code Online (Sandbox Code Playgroud)
已经my_memeber_t在头文件中定义为:
struct my_member_t {
struct complex_type * type;
char * name;
int default_number;
void * opaque;
};
Run Code Online (Sandbox Code Playgroud)
我在MSVC 9.0(Visual Studio 2008)中编译linux代码,在cygwin/MinGW上这可以正常工作.
但是cl无法编译这个(因为C99实现很糟糕):error C2059: syntax error : '.'
PROBLEM:
How to rewrite …
在Unix 一切都是文件的函数方法read(),write(),close()不支持在Win32.
我想效仿,但不知道如何时区分sock是插座或FD上WinSocks2.
//returns 1 if `sock` is network socket,
// 0 if `sock` is file desriptor (including stdio, stderr, stdout), ...
// -1 in none of above
int is_net_socket(int sock)
{
// ...?
}
Run Code Online (Sandbox Code Playgroud)
这应该如下:
int mysock = socket(PF_INET, SOCK_STREAM, 0);
int myfd = _open("my_file.txt", _O_RDONLY);
printf("1: %d 2: %d 3: %d 4:%d\n",
is_net_socket(mysock), //1
is_net_socket(myfd), //0
is_net_socket(stdin), //0
is_net_socket(stderr)); //0
// should print "1: 1 …Run Code Online (Sandbox Code Playgroud) 我无法在Lua中编写一个可以加载多个CPU的程序.由于Lua 通过协同程序支持这个概念,我相信它是可以实现的.
我失败的原因可能是:
更有经验的人(我两周前发现Lua)可以指出我正确的方向吗?
The point is to write a number-crunching script that does hi-load on ALL cores...
为了Lua的权力的示范目的.
谢谢...
让我们说我希望C macro适用于任何类型.我正在使用GCC编译器(> = 4.6)并且可以使用GNU99宏.
//code...
any_type_t *retVal = function_that_runs_very_long_time(a, b, &&c, **d, &e, *f);
//other code...
Run Code Online (Sandbox Code Playgroud)
用于TIMER的宏的用法可以看起来像这样
//code...
any_type_t *retVal =
TIMER(
function_that_runs_very_long_time(a, b, &&c, **d, &e, *f),
"TIMING FOR VALUE <%d, %d>", a, b
);
//other code...
Run Code Online (Sandbox Code Playgroud)
因此TIMER必须返回给定函数的值和其运行的打印持续时间.具有void返回类型的函数存在问题.
我显然可以有两个宏,如TIMER_TYPE和TIMER_VOID,但我想使用单一的时间函数与任何返回值.
谢谢你的建议.
编辑此TIMER宏的示例
#define TIMER(expr, fmt_msg, ...) \
({ \
struct timeval before, after; \
uint64_t time_span; \
int time_span_sec, time_span_usec; \
gettimeofday(&before, NULL); \
typeof(expr) _timer_expr__ = (expr); \ // <- static if?
gettimeofday(&after, NULL); \
time_span = …Run Code Online (Sandbox Code Playgroud) 在这里,Hello $world每个引用符号的解释我的意思是语言.
$world = "W?rl?"
"(Hell)*o $world\n" # <--- plain (Hell)*o, resolve $world, escape \n
'(Hell)*o $world\n' # <--- plain (Hell)*o, plain $world, escape \n
/(Hell)*o $world\n/ # <--- regexp (Hell)*, resolve $world, interpret \n
<(Hell)*o $world\n> # <--- make list ["(Hello*o", "$world\n"]
{(Hell)*o $world\n} # <--- syntax error, this language cant' parse it
Run Code Online (Sandbox Code Playgroud)
Perl 6也足够强大,可以在未来的语言中存在类似的东西
my $emacs_func = (defun perl-backward-to-start-of-continued-exp (lim)
(if (= (preceding-char) ?\))
(forward-sexp -1))
(beginning-of-line)
(if (<= (point) lim)
(goto-char (1+ lim))) …Run Code Online (Sandbox Code Playgroud) 基本上我想制作简单的切换程序(将映射到某些键盘快捷键),如果处于正常模式,则将任务栏设置为自动隐藏模式(相反,如果处于自动隐藏状态,则设置为正常显示模式).
你知道如何在C#中实现它吗?(或者Win32 C++,但实际上做的任何事情都可以.)
谢谢.希望我已经清楚了.
-
我真的不想要任何与任务栏重叠的全屏应用程序,只有切换显示模式和退出的无窗口程序.我定期从自动隐藏切换到普通视图,并希望简化它.(使用Win7.)
-
编辑.例如
#include <windows.h>
int CALLBACK WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
SetWindowPos(FindWindow(L"Shell_traywnd", NULL ), 0, 0, 0, 0, 0, 0x40);
}
Run Code Online (Sandbox Code Playgroud)
不会做的伎俩,它只显示任务栏,它已经可见=真,但没有将其切换为自动隐藏.(同样适用于0x80.)
编写一个函数,计算列表中大于或等于平均值的元素数(为简单起见,使用整数除法).
只使用single traversal列表结构!
我已经有了解决方案,但它涉及ref从闭包变化的变量foo'.
我对如何 在满足时功能 传递值[]感兴趣?
我天真的解决方案使用ref:
let foo ls =
let avg = ref 0
let rec foo' xs sumAcc lenAcc =
match xs with
| x'::xs' ->
let s = foo' xs' (x' + sumAcc) (1 + lenAcc)
if x' < !avg then s else s + 1
| [] ->
avg := (sumAcc / lenAcc) //? how to change THIS to functional …Run Code Online (Sandbox Code Playgroud) 有简单的密码将数字翻译成系列 . ( )
为了加密这个表示的数字(0 ... 2147483647),我(我想)我需要:
0 . 6 (()())
1 () 7 (...())
2 (()) 8 ((.()))
3 (.()) 9 (.(()))
4 ((())) 10 (().())
5 (..()) 11 (....())
227 (................................................())
2147483648 ((..........()))
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class P
{
static List<int> _list = new List<int>();
public static int Nth(int n)
{ …Run Code Online (Sandbox Code Playgroud) 我有(例如)不同泛型类型的词典(d1, d2, d3, d4),我想将它们存储在某些东西中
var d1 = new Dictionary<int, string>();
var d2 = new Dictionary<int, long>();
var d3 = new Dictionary<DateTime, bool>();
var d4 = new Dictionary<string, object>();
var something = ??? //new List<object> {d1, d2, d3, d4};
Run Code Online (Sandbox Code Playgroud)
是否有任何其他方式如何存储,在一些有共同点比不同object?
谢谢 :-)
我一直在努力使用C中的正则表达式(只是/usr/include/regex.h)。
我有(假设)数百个正则表达式,其中之一可以匹配输入字符串。目前,我正在这样做(实际上是在生成它):在匹配中进行数百次do-while,如果不匹配则中断并转到另一个。逐一:
do {
if ( regex_match(str, my_regex1) != MY_REGEX_SUCCESS ) DO_FAIL; //break
...
if ( sscanf(str, " %d.%d.%d.%d / %d ", &___ip1, &___ip2, &___ip3, &___ip4, &___pref) != 5 ) DO_FAIL; //break
...
} while (0);
do {
if ( regex_match(str, my_regex2) != MY_REGEX_SUCCESS ) DO_FAIL; //break
...
...
} while (0);
do {
if ( regex_match(str, my_regex3) != MY_REGEX_SUCCESS ) DO_FAIL; //break
...
...
} while (0);
Run Code Online (Sandbox Code Playgroud)
我想要的是这样的:
const char * match1 = "^([[:space:]]*)([$]([._a-zA-Z0-9-]{0,118})?[._a-zA-Z0-9])([[:space:]]*)$";
const char * …Run Code Online (Sandbox Code Playgroud) c ×4
c# ×3
windows ×2
animation ×1
c89 ×1
colors ×1
compile-time ×1
console ×1
coroutine ×1
emacs ×1
f# ×1
font-size ×1
generics ×1
grouping ×1
linux ×1
lisp ×1
list ×1
lua ×1
multicore ×1
optimization ×1
parsing ×1
performance ×1
perl ×1
perl6 ×1
posix ×1
primes ×1
raku ×1
regex ×1
sockets ×1
stream ×1
struct ×1
taskbar ×1
terminal ×1
traversal ×1
types ×1
unix ×1
visual-c++ ×1
void ×1
where-clause ×1
winsock ×1
winsock2 ×1