본문 바로가기

전체 글343

[Go] Slice Slice is a scalable collection type, unlike Array. Slice has advantages over Array in terms of memory usage and speed. Slice Declaration var slice []string slice = make([]string, 3) slice[0] = "hello" slice[2] = "hi" fmt.Println(slice[0], slice[1], slice[2]) // hello hi numSlice := make([]int, 3) numSlice[0] = 1 numSlice[1] = 2 numSlice[2] = 3 fmt.Println(numSlice[0], numSlice[1], numSlice[2]) /.. 2021. 10. 16.
[Go] Package A package is a bundle of structures, constants, variables, functions, etc. with the same purpose. Using Package If you want to use packages, use import keyword. import "fmt" You can alias to package. import htemplate "html/template" You can import packages even not used. import _ "math" In this case, you don't use the package, but you can get the effects of initializing the package. Go Module Th.. 2021. 10. 16.
[Go] Rune and String A string is a set of characters and a string is an immutable. Syntax A rune can be represented by '(single quote) and it means single character. Go supports UTF-8 as a standard character code. package main import "fmt" func main() { fmt.Printf("%c\n", 'G') fmt.Printf("%c\n", '고') fmt.Printf("%c\n", '去') } A string can be represented by "(double-quote) or `(backquote or backtick or grave). A spec.. 2021. 10. 16.
[Embedded] Unittest using GoogleTest on CMake In this posting, we will learn how to run a unittest for C. We will use GoogleTest and CMake for this. Prerequisite CMake Please refer to this post. 2021.10.13 - [Embedded] - [C] Build using CMake GoogleTest Clone the googletest into your project. $ git clone https://github.com/google/googletest/ Prepare Project This is the project tree. +-- src +-- main.c +-- calc.h +-- calc.c +-- googletest +-.. 2021. 10. 13.
[Embedded] Build using CMake CMake is an open-source, cross-platform build tool. In this posting, we will use CMake to build a C project. Prerequisite CMake You can install the latest CMake on this page. https://cmake.org/download/ I installed it with Homebrew. $ brew install cmake VSCode Extensions If you are using VSCode, you can install these extensions. It will help you a lot. Single File Project Let's create a project... 2021. 10. 13.
[Go] Pointer Pointer is a type that has a memory address as a value. Pointer Variable Defining a pointer variable uses a * symbol in front of the type. * symbol is also used to access the value of a pointer variable. And & symbol means the address of a variable. package main import "fmt" func main() { var pNum *int num := 7 // Assign address to pointer pNum = &num // Access to pointer fmt.Println(*pNum) // 7.. 2021. 10. 11.
[Go] Structure Structure consists of different types of values. The syntax is following: type STRUCT_NAME struct { FIELD_NAME DATA_TYPE ... } If the name of a structure starts with a capital letter, it is exported to the outside of the package. Structure Declaration var testStruct struct { numField float64 strField string boolField bool } fmt.Println(testStruct) // {0 false}] testStruct.numField = 7 testStruct.. 2021. 10. 11.
[Go] Array An array is a collection of values all of which have the same type. The value that an array has is called an element. The syntax of array definition is following: var VARIABLE_NAME [NUMBER_OF_ELEMENTS]DATA_TYPE var numArr [3]int numArr[0] = 1 numArr[1] = 2 numArr[2] = 3 fmt.Println(numArr[0], numArr[1], numArr[2]) // 1 2 3 An array is static. Therefore, it is not possible to add a new element af.. 2021. 10. 10.
[Go] Control Flow Like the other languages, Go has a similar syntax for control flow. Conditional Statement if Statement if CONDITION { STATEMENTS } else if CONDITION { STATEMENTS } else { STATEMENTS } Definitely, you know, if statements are executed only if the conditions are true. else if and else statements can be omitted. In addition, if statement can be nested. package main import "fmt" func main() { score :.. 2021. 10. 10.