小编sch*_*tbi的帖子

使用自动时不检查数组范围

使用编译此代码-Warray-bounds。声明array2时收到警告array index 3 is past the end of the array (which contains 3 elements)。但是,在声明array1时,即使它必须是相同的类型,从而携带相同的大小信息,也并非如此。这是c中的错误吗?

enum class Format : int {
  Off = 55,
  FormatA = 66,
  FormatB = 77,
};

inline Format (&AllFormats())[3] {
  static Format values[] = {
    Format::Off,
    Format::FormatA,
    Format::FormatB
  };
  return values;
}

int main()
{
    auto array1 = AllFormats();    
    auto v3 = array1[3];

    Format (&array2)[3] = AllFormats();    
    v3 = array2[3];
}
Run Code Online (Sandbox Code Playgroud)

c++ clang clang++

10
推荐指数
1
解决办法
257
查看次数

如何使用fmt库使用十进制逗号格式化浮点数?

我想使用fmt库格式化浮点数。

我尝试用小数点分隔符','格式化浮点数,并尝试此操作未成功:

#include <iostream>
#include <fmt/format.h>
#include <fmt/locale.h>

struct numpunct : std::numpunct<char> {
  protected:    
    char do_decimal_point() const override
    {
        return ',';
    }
};

int main(void) {
    std::locale loc;
    std::locale l(loc, new numpunct());
    std::cout << fmt::format(l, "{0:f}", 1.234567);
}
Run Code Online (Sandbox Code Playgroud)

输出为1.234567。我想要1,234567

更新:

我浏览了fmt库的源代码,并认为小数点分隔符已硬编码为浮点数,并且不遵守当前语言环境。

我刚在fmt库中打开一个问题

c++ fmt

10
推荐指数
1
解决办法
336
查看次数

如何在WinXP下获得准确的1ms计时器滴答

我试着每1毫秒调用一次函数.问题是,我喜欢用windows做这个.所以我尝试了多媒体时间API.

Multimediatimer API

资源

idTimer = timeSetEvent( 
     1, 
     0,
     TimerProc, 
     0, 
     TIME_PERIODIC|TIME_CALLBACK_FUNCTION ); 
Run Code Online (Sandbox Code Playgroud)

我的结果是大部分时间1毫秒都没问题,但有时我会得到双倍期.看看1.95ms附近的小凹凸 多媒体时间图http://www.freeimagehosting.net/uploads/8b78f2fa6d.png

我的第一个想法是,也许我的方法运行时间太长了.但我已经测量过了,情况并非如此.

排队计时器API

我的下一个尝试是使用queud计时器API

hTimerQueue = CreateTimerQueue();
if(hTimerQueue == NULL)
{
printf("Error creating queue: 0x%x\n", GetLastError());
}

BOOL res = CreateTimerQueueTimer(
&hTimer, 
hTimerQueue, 
TimerProc, 
NULL, 
0, 
1,  // 1ms
    WT_EXECUTEDEFAULT);
Run Code Online (Sandbox Code Playgroud)

但结果也不如预期.现在我大部分时间都是2毫秒的周期时间. queuedTimer http://www.freeimagehosting.net/uploads/2a46259a15.png

测量

为了测量时间,我使用了QueryPerformanceCounter和QueryPerformanceFrequency方法.

所以现在我的问题是,如果有人在Windows下遇到类似的问题,甚至可能找到解决方案?

谢谢.

c++ windows winapi real-time timer

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

是一个双向的Git < - > Svn Sync(都可写)可能吗?

我们团队的一部分发现git非常酷,并开始将其用作svn客户端.所以每个开发人员都有一个本地git存储库,并通过git-svn与svn同步.

然后我们想要对提交进行代码审查,并将补丁发送给同事进行审核.这种方法不是很直观,因为svn中SAME Revision 的校验和对于每个本地git存储库都是不同的.不知道为什么,因为内容应该是相同的.也许这是一个错误svn rebase

所以我们尝试在scm服务器上安装一个中央git存储库.现在每个使用git的开发人员都可以将他的更改推送到这个中央存储库,而另一个进行审查的开发人员可以将这些更改引入他的repo.不幸的是,因为每个开发人员都同时遇到svn rebase了校验和问题.

在阅读了很多帖子后,我认为管理具有subversion和git客户端的团队的最佳方法是:

  1. 一个中央Subversion存储库
  2. 中央Git存储库(源)
  3. 服务器上的中央Git工作副本
  4. 对于每个git开发人员一个本地git存储库
  5. 为每个svn开发人员提供一个普通的工作副本

现在我们需要一个中心工作来同步svn和git在服务器上的中央git工作副本上执行这样的常规脚本.

# First transfer the commits from git to svn
git checkout svnmaster
git pull origin svnmaster
git svn dcommit

# Now from svn to git
git svn rebase
git push origin svnmaster
Run Code Online (Sandbox Code Playgroud)

我现在的问题是:

  1. 这是最好的方法(没有切换到git completeley)
  2. 是否已有用于执行同步子弹证明的Windows脚本?
  3. 是否知道不同校验和的问题,是否有可能的解决方法?

谢谢你的每一个答案!

编辑 我最近发现了一个看起来非常有希望的项目:

SubGit

svn git

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

C#代码生成与正则表达式匹配的字符串

我使用正则表达式来验证用户输入.现在我可以配置正则表达式,因此它可以帮助用户查看如何格式化必须输入的示例.

是否有可能生成一些匹配任意正则表达式的字符串?甚至还有一个可以在某处使用的实现?

更新:由于许可证,我不能使用REX.还有其他可能吗?

c# regex

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

c#XML序列化:命名空间声明的顺序

我有一个非常奇怪的情况.我像这样序列化我的命名空间:

var namespaces = new XmlSerializerNamespaces();
namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");

serializer.Serialize(writer, config, namespaces);
Run Code Online (Sandbox Code Playgroud)

在我的机器上,我得到以下xml(一行我刚刚添加了换行符):

<SystemConfiguration 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns="http://www.schaeffler.com/sara/systemconfiguration/">
Run Code Online (Sandbox Code Playgroud)

在构建服务器上,我使用相同的软件:

<SystemConfiguration 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
      xmlns="http://www.schaeffler.com/sara/systemconfiguration/">
Run Code Online (Sandbox Code Playgroud)

你看到xsd和xsi的顺序是交换的.我检查了序列化程序的实现,发现顺序是用散列表确定的,并且XmlSerializerNamespaces没有接口为命名空间实现我自己的序列化程序.

这是XmlSerializationWriter中的方法:

protected void WriteNamespaceDeclarations(XmlSerializerNamespaces xmlns)
    {
      if (xmlns != null)
      {
        foreach (DictionaryEntry dictionaryEntry in xmlns.Namespaces)
        {
          string localName = (string) dictionaryEntry.Key;
          string ns = (string) dictionaryEntry.Value;
          if (this.namespaces != null)
          {
            string str = this.namespaces.Namespaces[(object) localName] as string;
            if (str != null && str != ns)
              throw new InvalidOperationException(Res.GetString("XmlDuplicateNs", (object) localName, (object) ns));
          }
          string …
Run Code Online (Sandbox Code Playgroud)

c# xml serialization

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

从exprtk编译win32库

我想从http://partow.net/programming/exprtk/index.html数学表达式库中编译win32 .dll或.lib .最简单的方法是什么?我正在使用MS VC++.

代码只有一个包含所有代码的.hpp.每次我编译我的程序都需要很长时间,因为它还编译exptrk.hpp文件(超过1,000kB的代码).

c++ math dll exprtk

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

是否可以将MongoDB用作嵌入式数据库?

正如标题所说,我喜欢将MongoDB服务器嵌入到我自己的C++应用程序中.我没有在文档中找到此模式.我在寻找的是嵌入式模式下的SQLite或Firebird.这对MongoDB也有可能吗?(不自己编程).

c++ embedded-database mongodb

8
推荐指数
2
解决办法
3485
查看次数

在共享内存数组中使用std :: string时c ++内存泄漏

我有这门课

class LayoutEntry
{
  unsigned int id_;
  string name_;  
  bool isInput_;
};
Run Code Online (Sandbox Code Playgroud)

复制构造函数如下所示:

LayoutEntry(const LayoutEntry &other)
        : id_(other.id_),
        name_(other.name_), 
        isInput_(other.isInput_)
    {
    }
Run Code Online (Sandbox Code Playgroud)

此类的对象放在另一个类中的地图内

class DataLayoutDescription 
{
    unsigned int sz_;
    set<LayoutEntry, SortByOffset> impl;

    // HERE!!!
    map<unsigned int, LayoutEntry> mapById;
Run Code Online (Sandbox Code Playgroud)

这个类的复制构造函数如下所示:

DataLayoutDescription::DataLayoutDescription(const DataLayoutDescription &other)
    :sz_(other.sz_), impl(other.impl), mapById(other.mapById)
{   
}
Run Code Online (Sandbox Code Playgroud)

现在的问题是:

  • 我在打印时运行每个LayoutEntry都会出现内存泄漏
  • 如果我mapById(other.mapById)在DataLayoutDescription的复制构造函数中删除,那么就没有memleak
  • 如果我删除name_(other.name_),内存泄漏也消失了

为什么?

编辑

对于测试我最后使用BOOST :: UnitTest我得到了内存泄漏转储

C:\wc\05_EAPGit\Debug>EapLibTest.exe --run-test=SharedVectorTest
Running 7 test cases...

*** No errors detected
Detected memory leaks!
Dumping objects ->
{1378} normal block at …
Run Code Online (Sandbox Code Playgroud)

c++ memory-leaks

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

Git:测试两个功能分支的组合

我为每个功能都有一个Git分支.但是,有时候,当A我在分支机构中进行开发时,我想测试一下A如果B应用的话也会如何表现.

目前,我用这个:

git checkout A
git branch base
git merge B
git reset --mixed base
git branch -D base
Run Code Online (Sandbox Code Playgroud)

有没有更短的方法来做到这一点?

另外:如果AB不共享同一个祖先怎么办?

o -- o -- o [A]
 \-- x -- o [v1_0]
           \ -- b1 -- b2 -- o [B]
Run Code Online (Sandbox Code Playgroud)

我怎么能更轻松地做这样的事情?

git checkout A
git branch ABase
git cherry-pick v1_0..B   // only applying b1,b2 not x
git reset --mixed ABase
git branch -D ABase
Run Code Online (Sandbox Code Playgroud)

git branching-strategy

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