Try โ€‚HackMD Logoโ€‰HackMD

2021q1 Homework4 (refinement)

contributed by < ccs100203 >

tags: linux2021

J09: refinement

ๅ•้กŒๆ•ด็†

  • ๅœจ qui3 ไธญ้‡ๅˆฐ็š„ xs_tmp๏ผŒๅ…ถไธญๅŒ…ๅซ็š„ struct ็”จ้€”ๆœชๆžๆ‡‚

็›ฎๅ‰้‚„ๆ˜ฏๆžไธๆ‡‚็‚บไป€้บผ _Static_assert ้œ€่ฆๅŒ…่ฃๅœจไธ€ๅ€‹ struct ่ฃก้ข

/* Memory leaks happen if the string is too long but it is still useful for
 * short strings.
 */
#define xs_tmp(x)                                                   \
    ((void) ((struct {                                              \
         _Static_assert(sizeof(x) <= MAX_STR_LEN, "it is too big"); \
         int dummy;                                                 \
     }){1}),                                                        \
     xs_new(&xs_literal_empty(), x))
  • quiz4 ไธญๅฐๆ–ผ pthread ไปฅๅŠ lock ็š„ๆŽŒๆกๅบฆไฝŽ (ๅทฒ็ถ“ๆžๆ‡‚)

  • ้ž้ž่ฟด็‰ˆๆœฌ INTROSORT ็š„่ฝ‰ๆ›ๆ™‚ๆฉŸ (็„ก MAX_LEVEL)